-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquirk-big-circuits.html
332 lines (308 loc) · 556 KB
/
quirk-big-circuits.html
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="keywords" content="quantum,circuit,simulator,quirk">
<meta name="description" content="Quirk is an open-source drag-and-drop quantum circuit simulator for exploring and understanding small quantum circuits.">
<title>Quirk: Quantum Circuit Simulator</title>
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAJGUlEQVRYw6WXa2xUZRrHf+fM6ZyZdmY6M50yhdJSoLWtWUkLQmvF1W2AaAvpiss2Gy9LrLIJGq/EWyKJbnYDiTHRbDXULWtEN1sNYMuWRaAuKoyASitgOr1bLG1HhplhzrRz6XTOfmjniG3xts/59J7znuf5v+9z+z8CPyBNTU3U1tYCUFFRgc/vswIlQCFQDjimt3qBk0AX0GG32QMul2uWjrlEuNaH5uZmampqKCouShpFNsr3RsPRnLKKsrx0W7pceF1hNkBPb4+il/T+lv0tF2Wj3B0NR/dMq+lwd7oDSV0/GUBjYyN1dXVJ4w/mLMlZs/WRratMVpPV6XTiPuum7NYyPAMeAJyLnZz66BRFy4rweDyEAqFA/av1p4f6h44Cb7g73YGkzpmimwtAd0+31ZHpKF+Qt2D7fXX3bdm2fVvxdddfZ8hakMVA5wCKpFBcWIzP4wMga1EWvaO9iOMiJWUl5OXnGW5ff/vS9PT0m1ApiEVjl10uV8Dr9UZ+FMD0qTevXrP6oYcfebi67NYyvdliBiDoDzIyOsKK0hWkyCn4PX4AbFk2suxZDA8PY7FYMBgNxMZjSDpJnzkv8waz1Zzf4+6RHZkO90wQuquvvbun2wpsvu2O2+599oVny3KX5iLLsra5v78fYpC9OBudqNNuICMrA1Encnn4MoZUA109XTz7xFMcP3WY8+52ll2/PDcj0zGvv7dfdGQ63Dt37oy0tLQAICYDbto/JavXrL7r6e1PL7ekW2YEi4CaUDGZTUiSNMttkiRhMpvQp+nZ9vBjWG8+y7q/DlH90hBvN79Ebl7u8qrfVt0FlNTV1dHc3DwFoKmpSYv2BXkLttx9z92rZxqfQiri9/ixOq3XTClHtoM3X3kL/cJRNj1lwZKlw5wt8OBbaZzo+DcrVq1YXbyseEtRcZG1pqaGpqYmxNraWi3a77zrzg2LixZfI10EImMRzFbzNQFkZmQyOZkgrIQ5dyLM6SaFeFglPqGiTggsK11G5drKDcCDRcVF1tra2ikXACULlyxcs2HTBlMy4GYajxNHVEVMsglp+tGJOnSiTluLiNy4cjme3gm+PDSGIzcFW6qOT5tCqFEjJouJDZs2mPKvz1+TrC3SdIVj6yNbV11tXEBARNSMH3EdQVVVuvq6CIfCRMYjtO5rBaB6YzXGNCPxeJzG3X/H2x/nxD/H6Dk5wZGGELGh+bz8tyew2KZce/+W+1c999hzVFRUIPn8PqtslO81W81WVVUJ+oNcHLmImlDxe/xExiKIqoiqqjAJY74xUuQU7Jl2qmqqprJgXga7d+3mixNfcNp1mrV3rKXugQfoaD+LTtSxueE+iKpc8V3BYrOQZkkz6A363/v8vg4JKImGo0udTidnT54lPBFG1smYzCYKbyjEbDVjkk109XUx5hujdGUpCRIAJMYSSIJEZnYm/X39tH/RzvKVy9n2wjYqVlZwx8bbuXT5EufPnMdkNBGdjGJMMTJ/wfxELBJbBJRI01eic591M2mZpKK0AkOqYVaqhUNhUuQUEiRQUbX3kZQIT/7pST7Y9wGV1ZXc88d7MOgNJEgQJ44tw8Yta24hHo8TGY/ganfhPetN3fLQlryG+oZCCVg3PDL8q9r7azFZTKioCHO0iMh4BHumXVurqEzGJ9n+5Hba2tqoqa3h5V0v4/f6ufzt5TnrRJoljXW3riMUDOH6i2sBsEgCKMgvMHsGPIwyOmd66UQdrftaqaqpIjGWAHUKQOv7rbS1tVFZWcnjzzxO4EIA7xUvB5sPovgUchbmzKlPURQK8gvMhziExC8QSZQYDYyiQ8ejzzzKpt9tIkVIIZ6I/3xdyX6+vna99VoukJCo3liNPdNOQX4B/nE/J988SdnaMuzpdgqWFSAIAgICfb19VG+spvymcuJ8H1BSdygYovVAq5IEcDg3N7fm1EenrD8UhIZUA2ElzDdD3/D5fz+nanMVvl4f8UQcQfgOcHQ8iiHVMOukVwehLqgjOzd7GBiUABrqG3zv/uddvMNeznec19LQ6rRqaWhMMzLoHsTr8XLjb27ElmrjW/VbENBuTERkIjpBmj1tKnCjEZSAQsATIKSEiE5GceqdOJY52P70dh/QJQEdslHu9ng8q0vLS7VCFEvE6DrXpRWiOHFOfXyKmytvxn/JTyQSwa9M8YG+3j6i41EmohOMDo7CEAyeGyQhJDCkGbA5bchWmSXzl2CxWWj/rJ1p6tYh2W32gM/v2xMKhDYKgmBNt6eTbk+fKsU3fFeK9x3ZR9mvy1hUtIjwWBjfJR8Hmw9qpdiQapg6+RAIToHKikokJFTUWbVDCSiBaDi6x26zBySXy0VRcRH1r9afLi0vXZfsByoqk0xqfWHj2o18+P6HFOYXfqfIpwBQflO59m7w3CCVFZUa8FkpGFR47dXXTgO4XC6tG3YM9Q8dPfDegZASVGb9pKIiIZEQEoSiIeLTT87CHHIW5mjrUDREQkhoJ5/L+IH3DoSmyWqHRkjcne4A8Mb+vfsPDLgH5sxXFRVDmgEloFwzp5WAgiHNMKdxgAH3APv37j+QZMoaIWlubsbd6Q4Mfz3c8M7b7xwPXgnO+jlBApvTRsATuCaAgCeAzWnTmtXVErwSZM/be44Pfz3ckJwVNEJSU1NDY2MjQMfxo8f37nhxx5mZIFRUBFEgpISIx+Nz5nlICSGIwqwbCF4JsuPFHWdcR117gY7GxkZtUNFYcUtLC16vN+LIdLgHewfFwcFBkzPDmZtqTtWYsV7SM+oZxZ5hn0XLw6EwIyMjLFm6BIPRoPm868su6l+pP/7J4U/+Bbzp7nQHkox4zrkgCeJC/4XO9o52WVTFxXn5eXpZlpENMr4RH+6LbvLz8r9Hy4+dPIZVbyW3IBdBELSA2/X6rr1fnfnqJeDQdKz9+GS0c+fOyO7G3V/LKXLbZ59+Fjr24THV6XBm+Hw+w7z58/Bd8DFv/jxGvhkhFothtpoZ7h4mZ2mOt6+nL7X7q+7A8089/3HbwbZ/KAHlz+5O9/dmgV88nOqN+j/EwjHH+jvXl07GJ235+flmgK7urouSTlIOthw8Jxvl8f97OP0J4znAuhnbDyeN/pzx/H9hJ0Pb7MiyZAAAAABJRU5ErkJggg==">
<!-- Whatever is between these start/end analytic tags is stripped by the 'downloading offline copy' code. -->
<!-- Start Analytics -->
<!-- End Analytics -->
</head>
<body style="margin: 0">
<!-- Primary content -->
<div id="inspectorDiv" style="display: none">
<!-- Buttons -->
<div style="margin: 5px;">
<button id="menu-button" style="min-width: 50px; min-height: 30px;">Menu</button>
<button id="export-button" style="min-width: 50px; min-height: 30px;">Export</button>
<button id="clear-circuit-button" style="min-width: 50px; min-height: 30px;">Clear Circuit</button>
<button id="clear-all-button" style="min-width: 50px; min-height: 30px;">Clear ALL</button>
<button id="undo-button" style="min-width: 50px; min-height: 30px;">Undo</button>
<button id="redo-button" style="min-width: 50px; min-height: 30px;">Redo</button>
<button id="gate-forge-button" style="min-width: 50px; min-height: 30px;">Make Gate</button>
<span style="color:#BBB">Version 2.1</span>
</div>
<!-- Circuit drawing area -->
<div id="canvasDiv" style="width: 100%; touch-action: manipulation; tab-index: 0; position: relative;">
<canvas id="drawCanvas"></canvas>
</div>
<div id="export-div" style="display:none;">
<div id="export-overlay" style="position:fixed; left: 0; top: 0; height: 100vh; width: 100vw; background: rgba(0, 0, 0, 0.7);">
</div>
<div style="position: absolute; top: 20px; left: 50px; padding: 20px; background-color: white; border: 1px solid black;">
<strong>Escaped Link</strong> - Link to current circuit, without special characters that confuse forums.
<div style="margin: 10px 0 30px 20px;">
<button tabindex="100" id="export-link-copy-button">Copy to Clipboard</button> <span id="export-link-copy-result"></span>
<div style="overflow:auto; word-wrap:break-word; max-height:60px; max-width:600px; border: 1px solid black; padding: 10px; margin: 2px;"><a tabindex="101" id="export-escaped-anchor"></a></div>
</div>
<strong>Offline Copy</strong> - Html file containing Quirk and the current circuit.
<div style="margin: 10px 0 30px 20px;">
<button tabindex="102" id="download-offline-copy-button" style="width:600px; height:60px;">Download ...</button>
</div>
<strong>JSON</strong> - Parsable representation of current circuit.
<div style="margin: 10px 0 0 20px;">
<button tabindex="103" id="export-json-copy-button">Copy to Clipboard</button> <span id="export-json-copy-result"></span>
<br>
<pre tabindex="104" id="export-circuit-json-pre" style="overflow:auto; max-width:600px; max-height:60px; border: 1px solid black; padding:5px; margin:2px;"></pre>
</div>
</div>
</div>
<div id="gate-forge-div" style="display:none">
<div id="gate-forge-overlay" style="position:fixed; left: 0; top: 0; height: 100vh; width: 100vw; background: rgba(0, 0, 0, 0.7);">
</div>
<div style="position: absolute; top: 20px; left: 50px; padding: 20px; background-color: white; border: 1px solid black;">
<style scoped>
th {
font-size: 20px;
}
</style>
<table cellspacing="0">
<colgroup>
<col style="background-color:#EEE;"/>
<col/>
<col style="background-color:#EEE;"/>
<col/>
<col style="background-color:#EEE;"/>
</colgroup>
<tr>
<th>From Rotation</th>
<th></th>
<th>From Matrix</th>
<th></th>
<th>From Circuit</th>
</tr>
<tr>
<td>
<input tabindex="100" id='gate-forge-rotation-axis' type="text" size="8" placeholder="X+Z"> axis<br/>
<input tabindex="101" id='gate-forge-rotation-angle' type="text" size="8" placeholder="45" style="margin:0.5em 0 0 0;">° angle<br/>
<input tabindex="102" id='gate-forge-rotation-phase' type="text" size="8" placeholder="0" style="margin:0.5em 0 0 0;">° phase
</td>
<td></td>
<td>
<style scoped>
input[type="checkbox"]:not(:checked) + label {
font-weight: bold;
background-color: pink;
}
</style>
<textarea tabindex="200" id="gate-forge-matrix" cols="25" rows="5" placeholder="1, i, i, 1"></textarea><br/>
<input tabindex="201" id="gate-forge-matrix-fix" type="checkbox" checked>
<label for="gate-forge-matrix-fix">ensure unitary (by SVD)</label>
</td>
<td></td>
<td>
From part of current circuit:<br/>
<input tabindex="300" id="gate-forge-circuit-cols" type="text" size="4" placeholder="1:∞" style="margin:0.5em 0 0 0;"> column range<br/>
<input tabindex="301" id="gate-forge-circuit-rows" type="text" size="4" placeholder="1:∞" style="margin:0.5em 0 0.5em 0;"> wire range<br/>
Inputs: <span id="gate-forge-circuit-inputs">(none)</span>, Weight: <span id="gate-forge-circuit-weight">0</span>
</td>
</tr>
<tr>
<td>
<canvas id="gate-forge-rotation-canvas" style="border:1px black solid;width:195px;height:100px;margin:10px 0 0 0;"></canvas>
</td>
<td> <strong>OR</strong> </td>
<td>
<canvas id="gate-forge-matrix-canvas" style="border:1px black solid;width:195px;height:100px;margin:10px 0 0 0;"></canvas>
</td>
<td> <strong>OR</strong> </td>
<td>
<canvas id="gate-forge-circuit-canvas" style="border:1px black solid;width:195px;height:100px;margin:10px 0 0 0;"></canvas>
</td>
</tr>
<tr>
<td>
<br/><input tabindex="110" id='gate-forge-rotation-name' type="text" placeholder="[the matrix]" style="width:7em;"> circuit symbol<br/><br/>
</td>
<td></td>
<td>
<br/><input tabindex="210" id='gate-forge-matrix-name' type="text" placeholder="[the matrix]" style="width:7em;"> circuit symbol<br/><br/>
</td>
<td></td>
<td>
<br/><input tabindex="310" id='gate-forge-circuit-name' type="text" placeholder="[the circuit]" style="width:7em;"> circuit symbol<br/><br/>
</td>
</tr>
<tr>
<td>
<button tabindex="120" id="gate-forge-rotation-button" style="width:100%;height:30px;">Create Rotation Gate</button>
</td>
<td></td>
<td>
<button tabindex="220" id="gate-forge-matrix-button" style="width:100%;height:30px;">Create Matrix Gate</button>
</td>
<td></td>
<td>
<button tabindex="320" id="gate-forge-circuit-button" style="width:100%;height:30px;">Create Circuit Gate</button>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="menu-div" style="display:block;">
<div id="menu-overlay" style="position:fixed; left: 0; top: 0; height: 100vh; width: 100vw; background: rgba(0, 0, 0, 0.7);">
</div>
<div style="position:absolute; top:20px; left:50px; margin:0;">
<div style="display:inline-block; padding:20px; background-color:white; border:1px solid black; text-align:center;">
<div style="font-size: 32px;">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAJGUlEQVRYw6WXa2xUZRrHf+fM6ZyZdmY6M50yhdJSoLWtWUkLQmvF1W2AaAvpiss2Gy9LrLIJGq/EWyKJbnYDiTHRbDXULWtEN1sNYMuWRaAuKoyASitgOr1bLG1HhplhzrRz6XTOfmjniG3xts/59J7znuf5v+9z+z8CPyBNTU3U1tYCUFFRgc/vswIlQCFQDjimt3qBk0AX0GG32QMul2uWjrlEuNaH5uZmampqKCouShpFNsr3RsPRnLKKsrx0W7pceF1hNkBPb4+il/T+lv0tF2Wj3B0NR/dMq+lwd7oDSV0/GUBjYyN1dXVJ4w/mLMlZs/WRratMVpPV6XTiPuum7NYyPAMeAJyLnZz66BRFy4rweDyEAqFA/av1p4f6h44Cb7g73YGkzpmimwtAd0+31ZHpKF+Qt2D7fXX3bdm2fVvxdddfZ8hakMVA5wCKpFBcWIzP4wMga1EWvaO9iOMiJWUl5OXnGW5ff/vS9PT0m1ApiEVjl10uV8Dr9UZ+FMD0qTevXrP6oYcfebi67NYyvdliBiDoDzIyOsKK0hWkyCn4PX4AbFk2suxZDA8PY7FYMBgNxMZjSDpJnzkv8waz1Zzf4+6RHZkO90wQuquvvbun2wpsvu2O2+599oVny3KX5iLLsra5v78fYpC9OBudqNNuICMrA1Encnn4MoZUA109XTz7xFMcP3WY8+52ll2/PDcj0zGvv7dfdGQ63Dt37oy0tLQAICYDbto/JavXrL7r6e1PL7ekW2YEi4CaUDGZTUiSNMttkiRhMpvQp+nZ9vBjWG8+y7q/DlH90hBvN79Ebl7u8qrfVt0FlNTV1dHc3DwFoKmpSYv2BXkLttx9z92rZxqfQiri9/ixOq3XTClHtoM3X3kL/cJRNj1lwZKlw5wt8OBbaZzo+DcrVq1YXbyseEtRcZG1pqaGpqYmxNraWi3a77zrzg2LixZfI10EImMRzFbzNQFkZmQyOZkgrIQ5dyLM6SaFeFglPqGiTggsK11G5drKDcCDRcVF1tra2ikXACULlyxcs2HTBlMy4GYajxNHVEVMsglp+tGJOnSiTluLiNy4cjme3gm+PDSGIzcFW6qOT5tCqFEjJouJDZs2mPKvz1+TrC3SdIVj6yNbV11tXEBARNSMH3EdQVVVuvq6CIfCRMYjtO5rBaB6YzXGNCPxeJzG3X/H2x/nxD/H6Dk5wZGGELGh+bz8tyew2KZce/+W+1c999hzVFRUIPn8PqtslO81W81WVVUJ+oNcHLmImlDxe/xExiKIqoiqqjAJY74xUuQU7Jl2qmqqprJgXga7d+3mixNfcNp1mrV3rKXugQfoaD+LTtSxueE+iKpc8V3BYrOQZkkz6A363/v8vg4JKImGo0udTidnT54lPBFG1smYzCYKbyjEbDVjkk109XUx5hujdGUpCRIAJMYSSIJEZnYm/X39tH/RzvKVy9n2wjYqVlZwx8bbuXT5EufPnMdkNBGdjGJMMTJ/wfxELBJbBJRI01eic591M2mZpKK0AkOqYVaqhUNhUuQUEiRQUbX3kZQIT/7pST7Y9wGV1ZXc88d7MOgNJEgQJ44tw8Yta24hHo8TGY/ganfhPetN3fLQlryG+oZCCVg3PDL8q9r7azFZTKioCHO0iMh4BHumXVurqEzGJ9n+5Hba2tqoqa3h5V0v4/f6ufzt5TnrRJoljXW3riMUDOH6i2sBsEgCKMgvMHsGPIwyOmd66UQdrftaqaqpIjGWAHUKQOv7rbS1tVFZWcnjzzxO4EIA7xUvB5sPovgUchbmzKlPURQK8gvMhziExC8QSZQYDYyiQ8ejzzzKpt9tIkVIIZ6I/3xdyX6+vna99VoukJCo3liNPdNOQX4B/nE/J988SdnaMuzpdgqWFSAIAgICfb19VG+spvymcuJ8H1BSdygYovVAq5IEcDg3N7fm1EenrD8UhIZUA2ElzDdD3/D5fz+nanMVvl4f8UQcQfgOcHQ8iiHVMOukVwehLqgjOzd7GBiUABrqG3zv/uddvMNeznec19LQ6rRqaWhMMzLoHsTr8XLjb27ElmrjW/VbENBuTERkIjpBmj1tKnCjEZSAQsATIKSEiE5GceqdOJY52P70dh/QJQEdslHu9ng8q0vLS7VCFEvE6DrXpRWiOHFOfXyKmytvxn/JTyQSwa9M8YG+3j6i41EmohOMDo7CEAyeGyQhJDCkGbA5bchWmSXzl2CxWWj/rJ1p6tYh2W32gM/v2xMKhDYKgmBNt6eTbk+fKsU3fFeK9x3ZR9mvy1hUtIjwWBjfJR8Hmw9qpdiQapg6+RAIToHKikokJFTUWbVDCSiBaDi6x26zBySXy0VRcRH1r9afLi0vXZfsByoqk0xqfWHj2o18+P6HFOYXfqfIpwBQflO59m7w3CCVFZUa8FkpGFR47dXXTgO4XC6tG3YM9Q8dPfDegZASVGb9pKIiIZEQEoSiIeLTT87CHHIW5mjrUDREQkhoJ5/L+IH3DoSmyWqHRkjcne4A8Mb+vfsPDLgH5sxXFRVDmgEloFwzp5WAgiHNMKdxgAH3APv37j+QZMoaIWlubsbd6Q4Mfz3c8M7b7xwPXgnO+jlBApvTRsATuCaAgCeAzWnTmtXVErwSZM/be44Pfz3ckJwVNEJSU1NDY2MjQMfxo8f37nhxx5mZIFRUBFEgpISIx+Nz5nlICSGIwqwbCF4JsuPFHWdcR117gY7GxkZtUNFYcUtLC16vN+LIdLgHewfFwcFBkzPDmZtqTtWYsV7SM+oZxZ5hn0XLw6EwIyMjLFm6BIPRoPm868su6l+pP/7J4U/+Bbzp7nQHkox4zrkgCeJC/4XO9o52WVTFxXn5eXpZlpENMr4RH+6LbvLz8r9Hy4+dPIZVbyW3IBdBELSA2/X6rr1fnfnqJeDQdKz9+GS0c+fOyO7G3V/LKXLbZ59+Fjr24THV6XBm+Hw+w7z58/Bd8DFv/jxGvhkhFothtpoZ7h4mZ2mOt6+nL7X7q+7A8089/3HbwbZ/KAHlz+5O9/dmgV88nOqN+j/EwjHH+jvXl07GJ235+flmgK7urouSTlIOthw8Jxvl8f97OP0J4znAuhnbDyeN/pzx/H9hJ0Pb7MiyZAAAAABJRU5ErkJggg=="/>
Welcome to Quirk
</div>
A drag-and-drop quantum circuit simulator.
<div style="margin:20px;">
<div id="loading-div" style="color:#D90; font-size:40px; display:block; height:120px; width:344px;">
Loading...
</div>
<button tabindex="50" id="close-menu-button" style="width:344px; height:120px; font-size:20px; display:none;">Edit Circuit</button>
</div>
<div style="display:inline-block; text-align:center; border:1px solid black; padding:4px; margin-right:64px;">
<a tabindex="51" href="https://www.youtube.com/watch?v=aloFwlBUwsQ">
<div style="width:128px;">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACt0lEQVQoz+3SP09TYRQG8IOL4RsgSNvbv4C4uMAkLgbippEw6CKwqIuGwW/gZEI6kIiDo0MnEk1MmEBLRQFbCnJLa6WlFK6K2kKrBarH55p7TUWa1vgm8pqe5Jc0vbfneZ+8JWYmmUl9+FqBWoFagf+hwP5Jn/TUQw/cgmG4Dz54DH4IQQwSkIaMgf+Q+bu0sStm7PYbWT4je9g4i36meio3a+2eOrgBGeBDKmOcse63Aql29yiwJO79cvjVE+4+YMn0/SyQbHNPA0tm+sfhV9rcdmBJOehNq2sQWFKDFG91eYEl5aXXLS4fsKR8FPM4A8BCtLq3hO2qToCiHqcKLMJOKrW3NnTzZbTFlRO1swKVlt1ODViEr9ks65NPpQor/VeCyx5XQdTuMjSKuBw5YBHMAvoU9/Z4MxzejvdeDOJZUVTGPjlS8UGUYkkBc/JbW7weCGRi53rm8c43kXk6euV0sCgHFTBv46OmcXp8/F3kTNeCyExadDhYlHIFSm/jbTLJqbGx9aWOjoiITFpw2FmUSgXM2/iwscFaIsHRgf7I32ZS2G5nUaopoM+237+61Nm5JCKT5hU7i1LxLxQKaerprrDITAopCotSrsAXVX0f6e4OiswyUdCmsCj7C+wkk9no+QtzeFYUmVOK5qxKDlgEs8CupuWjly7P4LtdUbvLyNGsVdGARSisJArxq9dmZ232gqidFWg0Y7GpwEJYlbywXdVR6UWzbQpYUlP0vNnmA5aUj6aPW73AkvLSsybrALCkBijQZFWAJaWQPlONlgCwZAJkztNGSy+wZHqpdJ4cs4wAS2KEDprJBssgJIEPqU24DnVUbiYamo/AKeiH23AXHsAjmISQIQ4J0CBjyAJX4bPx/idjh27R2DsBD43MUbgDQ3AWjv52YGaWWq1ArUCtQK3Av/UdR/1BF+14cggAAAAASUVORK5CYII=">
<div>Tutorial Video</div>
</div>
</a>
</div>
<div style="display:inline-block; text-align:center; border:1px solid black; padding:4px;">
<a tabindex="52" href="https://github.com/Strilanc/Quirk">
<div style="width:128px;">
<svg version="1.1" viewBox="0 0 16 16" width="48" height="48">
<path fill-rule="evenodd"
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">
</path>
</svg>
<div>Source Code</div>
</div>
</a>
</div>
</div>
<div style="display:inline-block; vertical-align:top; line-height:1.8; padding:15px 15px 15px 5px; background-color:#DDD; border:1px solid gray; margin:10px 0 0 -5px;">
Example Circuits<br>
<a id="example-anchor-grover">Grover Search</a><br>
<a id="example-anchor-shor">Shor Period Finding</a><br>
<a id="example-chsh-test">Bell Inequality Test (CHSH)</a><br>
<a id="example-anchor-teleport">Quantum Teleportation</a><br>
<a id="example-superdense-coding">Superdense Coding</a><br>
<a id="example-anchor-delayed-eraser">Delayed Choice Eraser</a><br>
<a id="example-symmetry-break">Symmetry Breaking</a><br>
<a id="example-qft">Quantum Fourier Transform</a><br>
<a id="example-addition">Reversible Addition</a><br>
</div>
</div>
</div>
<div id="error-div" style="display:none; font-size:24px; font-family:monospace; color:red;">
<div id="error-happened-div">An error happened. :(</div>
<div id="error-message-div" style="font-size: 16px;"></div>
<div id="error-known-div" style="font-size: 18px;">
<br>
<a id="error-known-issue-anchor">See more / complain about this issue on github</a>.
<br>
<br>
</div>
<div id="error-report-div">
<br>
Please report it:
<ul style="font-size: 18px;">
<li>
<a id="error-github-anchor">Create an issue on github</a>
(requires an account)
(repository: <a href="https://github.com/Strilanc/Quirk">Strilanc/Quirk</a>)
</li>
<li>
or <a id="error-mailto-anchor"></a>
</li>
</ul>
<br>
<br>
Useful details to mention (auto-included if you use the create/email links above):
<div style="font-size: 16px;">
<br>
<div id="error-description-div"></div>
<br>
PRE-DRAWN
<br>
<img id="error-image-pre" src="#" style="max-height: 250px; max-width: 600px"/>
<br>
POST-DRAWN
<br>
<img id="error-image-post" src="#" style="max-height: 250px; max-width: 600px"/>
</div>
</div>
</div>
<!-- Javascript detection -->
<div id="noscript-div" class="noscript-warning" style="
animation-duration: 3.0s;
-moz-animation-duration: 3.0s;
-webkit-animation-duration: 3.0s;
-o-animation-duration: 3.0s;
animation-name: delay-showing-before-hide-script-can-run-but-then-jump-in;
-moz-animation-name: delay-showing-before-hide-script-can-run-but-then-jump-in;
-webkit-animation-name: delay-showing-before-hide-script-can-run-but-then-jump-in;
-o-animation-name: delay-showing-before-hide-script-can-run-but-then-jump-in;
background-color: white;
border: 1px solid red;
padding: 10px;">
<style scoped>
@keyframes delay-showing-before-hide-script-can-run-but-then-jump-in {
from { opacity: 0; }
95% { opacity: 0; }
to { opacity: 1; }
}
@-webkit-keyframes delay-showing-before-hide-script-can-run-but-then-jump-in {
from { opacity: 0; }
95% { opacity: 0; }
to { opacity: 1; }
}
@-moz-keyframes delay-showing-before-hide-script-can-run-but-then-jump-in {
from { opacity: 0; }
95% { opacity: 0; }
to { opacity: 1; }
}
@-o-keyframes delay-showing-before-hide-script-can-run-but-then-jump-in {
from { opacity: 0; }
95% { opacity: 0; }
to { opacity: 1; }
}
.noscript-warning {
color: red;
font-size: 24px;
position: absolute;
top: 25%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
You appear to have JavaScript blocked. And Quirk is made out of JavaScript... :(
</div>
<script>
document.getElementById('noscript-div').style.display = 'none';
</script>
<script>
document.getElementById('noscript-div').style.display = 'block';
//noinspection InnerHTMLJS
document.QUIRK_QUINE_ALL_HTML_ORIGINAL = '<!'+'DOCTYPE html>\n<'+'html>\n ' +
document.documentElement.innerHTML + '\n<' + '/html>';
document.getElementById('noscript-div').style.display = 'none';
//DEFAULT_CIRCUIT_START
document.DEFAULT_CIRCUIT = undefined;
//DEFAULT_CIRCUIT_END
// UN-MINIFIED SOURCE IS AVAILABLE FROM github.com/Strilanc/Quirk
!function(e){"use strict";function t(e){e.Reflect=e.Reflect||{},e.Reflect.global=e.Reflect.global||e}if(!e.$traceurRuntime){t(e);e.$traceurRuntime={options:{},setupGlobals:t,typeof:function(e){return typeof e}}}}("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this),function(){function e(e,t,r,n,i,a,o){var u=[];return e&&u.push(e,":"),r&&(u.push("//"),t&&u.push(t,"@"),u.push(r),n&&u.push(":",n)),i&&u.push(i),a&&u.push("?",a),o&&u.push("#",o),u.join("")}function t(e){return e.match(i)}function r(e){if("/"===e)return"/";for(var t="/"===e[0]?"/":"",r="/"===e.slice(-1)?"/":"",n=e.split("/"),i=[],a=0,o=0;o<n.length;o++){var u=n[o];switch(u){case"":case".":break;case"..":i.length?i.pop():a++;break;default:i.push(u)}}if(!t){for(;a-- >0;)i.unshift("..");0===i.length&&i.push(".")}return t+i.join("/")+r}function n(t){var n=t[a.PATH]||"";return n=r(n),t[a.PATH]=n,e(t[a.SCHEME],t[a.USER_INFO],t[a.DOMAIN],t[a.PORT],t[a.PATH],t[a.QUERY_DATA],t[a.FRAGMENT])}var i=new RegExp("^(?:([^:/?#.]+):)?(?://(?:([^/?#]*)@)?([\\w\\d\\-\\u0100-\\uffff.%]*)(?::([0-9]+))?)?([^?#]+)?(?:\\?([^#]*))?(?:#(.*))?$"),a={SCHEME:1,USER_INFO:2,DOMAIN:3,PORT:4,PATH:5,QUERY_DATA:6,FRAGMENT:7};$traceurRuntime.canonicalizeUrl=function(e){return n(t(e))},$traceurRuntime.isAbsolute=function(e){return!(!e||"/"!==e[0]&&!t(e)[a.SCHEME])},$traceurRuntime.removeDotSegments=r,$traceurRuntime.resolveUrl=function(e,r){var i=t(r),o=t(e);if(i[a.SCHEME])return n(i);i[a.SCHEME]=o[a.SCHEME];for(var u=a.SCHEME;u<=a.PORT;u++)i[u]||(i[u]=o[u]);if("/"==i[a.PATH][0])return n(i);var s=o[a.PATH],c=s.lastIndexOf("/");return s=s.slice(0,c+1)+i[a.PATH],i[a.PATH]=s,n(i)}}(),function(e){"use strict";function t(e,t){this.url=e,this.value_=t}function r(e,t){this.message=this.constructor.name+": "+this.stripCause(t)+" in "+e,t instanceof r||!t.stack?this.stack="":this.stack=this.stripStack(t.stack)}function n(e,t){var r=[],n=t-3;n<0&&(n=0);for(var i=n;i<t;i++)r.push(e[i]);return r}function i(e,t){var r=t+1;r>e.length-1&&(r=e.length-1);for(var n=[],i=t;i<=r;i++)n.push(e[i]);return n}function a(e){for(var t="",r=0;r<e-1;r++)t+="-";return t}function o(e,r){t.call(this,e,null),this.func=r}function u(e){if(e){var t=v.normalize(e);return h[t]}}function s(e){var t=arguments[1],r=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(n){var i,a;if(t===p){var o=Object.getOwnPropertyDescriptor(e,n);o.get&&(i=o.get)}i||(a=e[n],i=function(){return a}),Object.defineProperty(r,n,{get:i,enumerable:!0})}),Object.preventExtensions(r),r}var c,l=$traceurRuntime,d=l.canonicalizeUrl,m=l.resolveUrl,f=l.isAbsolute,h=Object.create(null);c=e.location&&e.location.href?m(e.location.href,"./"):"",r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r.prototype.stripError=function(e){return e.replace(/.*Error:/,this.constructor.name+":")},r.prototype.stripCause=function(e){return e?e.message?this.stripError(e.message):e+"":""},r.prototype.loadedBy=function(e){this.stack+="\n loaded by "+e},r.prototype.stripStack=function(e){var t=[];return e.split("\n").some(function(e){if(/UncoatedModuleInstantiator/.test(e))return!0;t.push(e)}),t[0]=this.stripError(t[0]),t.join("\n")},(o.prototype=Object.create(t.prototype)).getUncoatedModule=function(){var t=this;if(this.value_)return this.value_;try{var o;return void 0!==typeof $traceurRuntime&&$traceurRuntime.require&&(o=$traceurRuntime.require.bind(null,this.url)),this.value_=this.func.call(e,o)}catch(e){if(e instanceof r)throw e.loadedBy(this.url),e;if(e.stack){var u=this.func.toString().split("\n"),s=[];e.stack.split("\n").some(function(e,r){if(e.indexOf("UncoatedModuleInstantiator.getUncoatedModule")>0)return!0;var o=/(at\s[^\s]*\s).*>:(\d*):(\d*)\)/.exec(e);if(o){var c=parseInt(o[2],10);s=s.concat(n(u,c)),1===r?s.push(a(o[3])+"^ "+t.url):s.push(a(o[3])+"^"),(s=s.concat(i(u,c))).push("= = = = = = = = =")}else s.push(e)}),e.stack=s.join("\n")}throw new r(this.url,e)}};var g=Object.create(null),p={},v={normalize:function(e,t,r){if("string"!=typeof e)throw new TypeError("module name must be a string, not "+typeof e);if(f(e))return d(e);if(/[^\.]\/\.\.\//.test(e))throw new Error("module name embeds /../: "+e);return"."===e[0]&&t?m(t,e):d(e)},get:function(e){var t=u(e);if(t){var r=g[t.url];return r||(r=s(t.getUncoatedModule(),p),g[t.url]=r)}},set:function(e,t){e=String(e),h[e]=new o(e,function(){return t}),g[e]=t},get baseURL(){return c},set baseURL(e){c=String(e)},registerModule:function(e,t,r){var n=v.normalize(e);if(h[n])throw new Error("duplicate module named "+n);h[n]=new o(n,r)},bundleStore:Object.create(null),register:function(e,t,r){t&&(t.length||r.length)?this.bundleStore[e]={deps:t,execute:function(){var e=arguments,n={};t.forEach(function(t,r){return n[t]=e[r]});var i=r.call(this,n);return i.execute.call(this),i.exports}}:this.registerModule(e,t,r)},getAnonymousModule:function(e){return new s(e(),p)}},y=new s({ModuleStore:v});v.set("@traceur/src/runtime/ModuleStore.js",y);var b=$traceurRuntime.setupGlobals;$traceurRuntime.setupGlobals=function(e){b(e)},$traceurRuntime.ModuleStore=v,$traceurRuntime.registerModule=v.registerModule.bind(v),$traceurRuntime.getModule=v.get,$traceurRuntime.setModule=v.set,$traceurRuntime.normalizeModuleName=v.normalize}("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this),$traceurRuntime.registerModule("[email protected]/src/runtime/new-unique-string.js",[],function(){"use strict";function e(){return"__$"+(1e9*t()>>>1)+"$"+ ++r+"$__"}var t=Math.random,r=Date.now()%1e9;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/has-native-symbols.js",[],function(){"use strict";function e(){return t}var t=!!Object.getOwnPropertySymbols&&"function"==typeof Symbol;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/symbols.js",[],function(){"use strict";function e(e){return{configurable:!0,enumerable:!1,value:e,writable:!0}}function t(e){var t=u();l(this,v,{value:this}),l(this,g,{value:t}),l(this,p,{value:e}),d(this),y[t]=this}function r(e){return y[e]}function n(e){for(var t=[],n=0;n<e.length;n++)r(e[n])||t.push(e[n]);return t}function i(e){return n(m(e))}function a(e){return n(f(e))}function o(e){for(var t=[],r=m(e),n=0;n<r.length;n++){var i=y[r[n]];i&&t.push(i)}return t}var u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../new-unique-string.js","[email protected]/src/runtime/modules/symbols.js")).default,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../has-native-symbols.js","[email protected]/src/runtime/modules/symbols.js")).default,c=Object.create,l=Object.defineProperty,d=Object.freeze,m=Object.getOwnPropertyNames,f=Object.keys,h=TypeError,g=u(),p=u(),v=u(),y=c(null),b=function(e){var r=new t(e);if(!(this instanceof b))return r;throw new h("Symbol cannot be new'ed")};l(b.prototype,"constructor",e(b)),l(b.prototype,"toString",e(function(){return this[v][g]})),l(b.prototype,"valueOf",e(function(){var e=this[v];if(!e)throw h("Conversion from symbol to string");return e[g]})),l(t.prototype,"constructor",e(b)),l(t.prototype,"toString",{value:b.prototype.toString,enumerable:!1}),l(t.prototype,"valueOf",{value:b.prototype.valueOf,enumerable:!1}),d(t.prototype),function(t){var r=t.Object;s()||(t.Symbol=b,r.getOwnPropertyNames=i,r.keys=a,l(r,"getOwnPropertySymbols",e(o))),t.Symbol.iterator||(t.Symbol.iterator=t.Symbol("Symbol.iterator")),t.Symbol.observer||(t.Symbol.observer=t.Symbol("Symbol.observer"))}("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:void 0);var R=s()?function(e){return typeof e}:function(e){return e instanceof t?"symbol":typeof e};return{get typeof(){return R}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/typeof.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./symbols.js","[email protected]/src/runtime/modules/typeof.js"));return{get default(){return e.typeof}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/symbols.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/typeof.js","[email protected]/src/runtime/symbols.js")).default;return $traceurRuntime.typeof=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/createClass.js",[],function(){"use strict";function e(e,t){m(e).forEach(t),f&&f(e).forEach(t)}function t(t){var r={};return e(t,function(e){r[e]=d(t,e),r[e].enumerable=!1}),r}function r(t){e(t,function(e){l(t,e,h)})}function n(e,n,a,o){return l(n,"constructor",{value:e,configurable:!0,enumerable:!1,writable:!0}),arguments.length>3?("function"==typeof o&&(e.__proto__=o),e.prototype=s(i(o),t(n))):(r(n),e.prototype=n),l(e,"prototype",{configurable:!1,writable:!1}),c(e,t(a))}function i(e){if("function"==typeof e){var t=e.prototype;if(a(t)===t||null===t)return e.prototype;throw new o("super prototype must be an Object or null")}if(null===e)return null;throw new o("Super expression must either be null or a function, not "+typeof e+".")}var a=Object,o=TypeError,u=Object,s=u.create,c=u.defineProperties,l=u.defineProperty,d=u.getOwnPropertyDescriptor,m=u.getOwnPropertyNames,f=u.getOwnPropertySymbols,h={enumerable:!1};return{get default(){return n}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/superConstructor.js",[],function(){"use strict";function e(e){return e.__proto__}return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/superDescriptor.js",[],function(){"use strict";function e(e,t){var i=n(e);do{var a=r(i,t);if(a)return a;i=n(i)}while(i)}var t=Object,r=t.getOwnPropertyDescriptor,n=t.getPrototypeOf;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/superGet.js",[],function(){"use strict";function e(e,r,n){var i=t(r,n);if(i){var a=i.value;return a||(i.get?i.get.call(e):a)}}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./superDescriptor.js","[email protected]/src/runtime/modules/superGet.js")).default;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/superSet.js",[],function(){"use strict";function e(e,n,i,a){var o=t(n,i);if(o&&o.set)return o.set.call(e,a),a;throw r("super has no setter '"+i+"'.")}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./superDescriptor.js","[email protected]/src/runtime/modules/superSet.js")).default,r=TypeError;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/classes.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/createClass.js","[email protected]/src/runtime/classes.js")).default,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/superConstructor.js","[email protected]/src/runtime/classes.js")).default,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/superGet.js","[email protected]/src/runtime/classes.js")).default,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/superSet.js","[email protected]/src/runtime/classes.js")).default;return $traceurRuntime.createClass=e,$traceurRuntime.superConstructor=t,$traceurRuntime.superGet=r,$traceurRuntime.superSet=n,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/exportStar.js",[],function(){"use strict";function e(e){for(var t=arguments,i=1;i<arguments.length;i++)!function(i){var a=t[i],o=n(a);e:for(var u=0;u<o.length;u++)switch(function(t){var n=o[t];if("__esModule"===n||"default"===n)return 0;r(e,n,{get:function(){return a[n]},enumerable:!0})}(u)){case 0:continue e}}(i);return e}var t=Object,r=t.defineProperty,n=t.getOwnPropertyNames;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/exportStar.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/exportStar.js","[email protected]/src/runtime/exportStar.js")).default;return $traceurRuntime.exportStar=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/private-symbol.js",[],function(){"use strict";function e(e){return l[e]}function t(){var e=(s||u)();return l[e]=!0,e}function r(e,t){return hasOwnProperty.call(e,t)}function n(e,t){return!!r(e,t)&&(delete e[t],!0)}function i(e,t,r){e[t]=r}function a(e,t){var r=e[t];if(void 0!==r)return hasOwnProperty.call(e,t)?r:void 0}function o(){c&&(Object.getOwnPropertySymbols=function(t){for(var r=[],n=c(t),i=0;i<n.length;i++){var a=n[i];e(a)||r.push(a)}return r})}var u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./new-unique-string.js","[email protected]/src/runtime/private-symbol.js")).default,s="function"==typeof Symbol?Symbol:void 0,c=Object.getOwnPropertySymbols,l=(0,Object.create)(null);return{get isPrivateSymbol(){return e},get createPrivateSymbol(){return t},get hasPrivate(){return r},get deletePrivate(){return n},get setPrivate(){return i},get getPrivate(){return a},get init(){return o}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/private-weak-map.js",[],function(){"use strict";function e(e){return!1}function t(){return new u}function r(e,t){return t.has(e)}function n(e,t){return t.delete(e)}function i(e,t,r){t.set(e,r)}function a(e,t){return t.get(e)}function o(){}var u="function"==typeof WeakMap?WeakMap:void 0;return{get isPrivateSymbol(){return e},get createPrivateSymbol(){return t},get hasPrivate(){return r},get deletePrivate(){return n},get setPrivate(){return i},get getPrivate(){return a},get init(){return o}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/private.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./private-symbol.js","[email protected]/src/runtime/private.js")),t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./private-weak-map.js","[email protected]/src/runtime/private.js")),r="function"==typeof WeakMap?t:e,n=r.isPrivateSymbol,i=r.createPrivateSymbol,a=r.hasPrivate,o=r.deletePrivate,u=r.setPrivate,s=r.getPrivate;return r.init(),{get isPrivateSymbol(){return n},get createPrivateSymbol(){return i},get hasPrivate(){return a},get deletePrivate(){return o},get setPrivate(){return u},get getPrivate(){return s}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/properTailCalls.js",[],function(){"use strict";function e(e,t,r){return[h,e,t,r]}function t(e){return e&&e[0]===h}function r(e,t,r){for(var n=[t],i=0;i<r.length;i++)n[i+1]=r[i];return f(Function.prototype.bind,e,n)}function n(e,t){return new(r(e,null,t))}function i(e){return!!l(e,g)}function a(r,n,a){var o=a[0];if(t(o))return o=f(r,n,o[3]);for(o=e(r,n,a);;){if(o=i(r)?f(r,o[2],[o]):f(r,o[2],o[3]),!t(o))return o;r=o[1]}}function o(){return i(this)?n(this,[e(null,null,arguments)]):n(this,arguments)}function u(){g=m(),Function.prototype.call=s(function(t){return a(function(t){for(var r=[],n=1;n<arguments.length;++n)r[n-1]=arguments[n];return e(this,t,r)},this,arguments)}),Function.prototype.apply=s(function(t,r){return a(function(t,r){return e(this,t,r)},this,arguments)})}function s(e){return null===g&&u(),d(e,g,!0),e}var c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/modules/properTailCalls.js")),l=c.getPrivate,d=c.setPrivate,m=c.createPrivateSymbol,f=Function.prototype.call.bind(Function.prototype.apply),h=Object.create(null),g=null;return{get createContinuation(){return e},get tailCall(){return a},get construct(){return o},get initTailRecursiveFunction(){return s}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/initTailRecursiveFunction.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./properTailCalls.js","[email protected]/src/runtime/modules/initTailRecursiveFunction.js"));return{get default(){return e.initTailRecursiveFunction}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/call.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./properTailCalls.js","[email protected]/src/runtime/modules/call.js"));return{get default(){return e.tailCall}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/continuation.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./properTailCalls.js","[email protected]/src/runtime/modules/continuation.js"));return{get default(){return e.createContinuation}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/construct.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./properTailCalls.js","[email protected]/src/runtime/modules/construct.js"));return{get default(){return e.construct}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/properTailCalls.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/initTailRecursiveFunction.js","[email protected]/src/runtime/properTailCalls.js")).default,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/call.js","[email protected]/src/runtime/properTailCalls.js")).default,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/continuation.js","[email protected]/src/runtime/properTailCalls.js")).default,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/construct.js","[email protected]/src/runtime/properTailCalls.js")).default;return $traceurRuntime.initTailRecursiveFunction=e,$traceurRuntime.call=t,$traceurRuntime.continuation=r,$traceurRuntime.construct=n,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/relativeRequire.js",[],function(){"use strict";var e;return $traceurRuntime.require=function(t,r){if(e=e||"undefined"!=typeof require&&require("path"),!("/"===r.slice(-1)||"/"===r[0]))return"."===r[0]?require(e.resolve(e.dirname(t),r)):require(r)},{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/checkObjectCoercible.js",[],function(){"use strict";function e(e){if(null===e||void 0===e)throw new t("Value cannot be converted to an Object");return e}var t=TypeError;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/spread.js",[],function(){"use strict";function e(){for(var e,r=[],n=0,i=0;i<arguments.length;i++){var a=t(arguments[i]);if("function"!=typeof a[Symbol.iterator])throw new TypeError("Cannot spread non-iterable object.");for(var o=a[Symbol.iterator]();!(e=o.next()).done;)r[n++]=e.value}return r}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../checkObjectCoercible.js","[email protected]/src/runtime/modules/spread.js")).default;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/spread.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/spread.js","[email protected]/src/runtime/spread.js")).default;return $traceurRuntime.spread=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/iteratorToArray.js",[],function(){"use strict";function e(e){for(var t,r=[],n=0;!(t=e.next()).done;)r[n++]=t.value;return r}return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/destructuring.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/iteratorToArray.js","[email protected]/src/runtime/destructuring.js")).default;return $traceurRuntime.iteratorToArray=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/async.js",[],function(){"use strict";function e(){}function t(){}function r(e){return e.prototype=m(t.prototype),e.__proto__=t,e}function n(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=m(t.prototype);return l(i,h,e),i}function i(e,t){return new Promise(function(r,n){var i=e({next:function(e){return t.call(i,e)},throw:function(e){n(e)},return:function(e){r(e)}})})}function a(e){return Promise.resolve().then(e)}function o(e,t){return new y(e,t)}var u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/modules/async.js")),s=u.createPrivateSymbol,c=u.getPrivate,l=u.setPrivate,d=Object,m=d.create,f=d.defineProperty,h=s();e.prototype=t,t.constructor=e,f(t,"constructor",{enumerable:!1});var g=function(){return $traceurRuntime.createClass(function(e){var t=this;this.decoratedObserver=o(e,function(){t.done=!0}),this.done=!1,this.inReturn=!1},{throw:function(e){if(!this.inReturn)throw e},yield:function(e){if(this.done)throw void(this.inReturn=!0);var t;try{t=this.decoratedObserver.next(e)}catch(e){throw this.done=!0,e}if(void 0!==t){if(t.done)throw this.done=!0,void(this.inReturn=!0);return t.value}},yieldFor:function(e){var t=this;return i(e[Symbol.observer].bind(e),function(e){if(t.done)this.return();else{var r;try{r=t.decoratedObserver.next(e)}catch(e){throw t.done=!0,e}if(void 0!==r)return r.done&&(t.done=!0),r}})}},{})}();t.prototype[Symbol.observer]=function(e){var t=c(this,h),r=new g(e);return a(function(){return t(r)}).then(function(e){r.done||r.decoratedObserver.return(e)}).catch(function(e){r.done||r.decoratedObserver.throw(e)}),r.decoratedObserver},f(t.prototype,Symbol.observer,{enumerable:!1});var p=Symbol(),v=Symbol(),y=function(){return $traceurRuntime.createClass(function(e,t){this[p]=e,this[v]=t},{next:function(e){var t=this[p].next(e);return void 0!==t&&t.done&&this[v].call(this),t},throw:function(e){return this[v].call(this),this[p].throw(e)},return:function(e){return this[v].call(this),this[p].return(e)}},{})}();return Array.prototype[Symbol.observer]=function(e){var t=!1,r=o(e,function(){return t=!0}),n=!0,i=!1,a=void 0;try{for(var u=void 0,s=this[Symbol.iterator]();!(n=(u=s.next()).done);n=!0){var c=u.value;if(r.next(c),t)return}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r.return(),r},f(Array.prototype,Symbol.observer,{enumerable:!1}),{get initAsyncGeneratorFunction(){return r},get createAsyncGeneratorInstance(){return n},get observeForEach(){return i},get schedule(){return a},get createDecoratedGenerator(){return o}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/initAsyncGeneratorFunction.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/modules/initAsyncGeneratorFunction.js"));return{get default(){return e.initAsyncGeneratorFunction}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/createAsyncGeneratorInstance.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/modules/createAsyncGeneratorInstance.js"));return{get default(){return e.createAsyncGeneratorInstance}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/observeForEach.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/modules/observeForEach.js"));return{get default(){return e.observeForEach}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/schedule.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/modules/schedule.js"));return{get default(){return e.schedule}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/createDecoratedGenerator.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/modules/createDecoratedGenerator.js"));return{get default(){return e.createDecoratedGenerator}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/async.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/initAsyncGeneratorFunction.js","[email protected]/src/runtime/async.js")).default,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/createAsyncGeneratorInstance.js","[email protected]/src/runtime/async.js")).default,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/observeForEach.js","[email protected]/src/runtime/async.js")).default,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/schedule.js","[email protected]/src/runtime/async.js")).default,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/createDecoratedGenerator.js","[email protected]/src/runtime/async.js")).default;return $traceurRuntime.initAsyncGeneratorFunction=e,$traceurRuntime.createAsyncGeneratorInstance=t,$traceurRuntime.observeForEach=r,$traceurRuntime.schedule=n,$traceurRuntime.createDecoratedGenerator=i,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/generators.js",[],function(){"use strict";function e(e){return{configurable:!0,enumerable:!1,value:e,writable:!0}}function t(e){return new Error("Traceur compiler bug: invalid state in state machine: "+e)}function r(){this.state=0,this.GState=w,this.storedException=void 0,this.finallyFallThrough=void 0,this.sent_=void 0,this.returnValue=void 0,this.oldReturnValue=void 0,this.tryStack_=[]}function n(e,t,r,n){switch(e.GState){case M:throw new Error('"'+r+'" on executing generator');case x:if("next"==r)return{value:void 0,done:!0};if(n===S)return{value:e.returnValue,done:!0};throw n;case w:if("throw"===r){if(e.GState=x,n===S)return{value:e.returnValue,done:!0};throw n}if(void 0!==n)throw p("Sent value to newborn generator");case _:e.GState=M,e.action=r,e.sent=n;var i;try{i=t(e)}catch(t){if(t!==S)throw t;i=e}var a=i===e;return a&&(i=e.returnValue),e.GState=a?x:_,{value:i,done:a}}}function i(){}function a(){}function o(e,t,n){var i=l(e,n),a=new r,o=y(t.prototype);return g(o,T,a),g(o,A,i),o}function u(e){return e.prototype=y(a.prototype),e.__proto__=a,e}function s(){r.call(this),this.err=void 0;var e=this;e.result=new Promise(function(t,r){e.resolve=t,e.reject=r})}function c(e,t){var r=l(e,t),n=new s;return n.createCallback=function(e){return function(t){n.state=e,n.value=t,r(n)}},n.errback=function(e){d(n,e),r(n)},r(n),n.result}function l(e,t){return function(r){for(;;)try{return e.call(t,r)}catch(e){d(r,e)}}}function d(e,t){e.storedException=t;var r=e.tryStack_[e.tryStack_.length-1];r?(e.state=void 0!==r.catch?r.catch:r.finally,void 0!==r.finallyFallThrough&&(e.finallyFallThrough=r.finallyFallThrough)):e.handleException(t)}var m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/modules/generators.js")),f=m.createPrivateSymbol,h=m.getPrivate,g=m.setPrivate,p=TypeError,v=Object,y=v.create,b=v.defineProperties,R=v.defineProperty,w=0,M=1,_=2,x=3,S={};r.prototype={pushTry:function(e,t){if(null!==t){for(var r=null,n=this.tryStack_.length-1;n>=0;n--)if(void 0!==this.tryStack_[n].catch){r=this.tryStack_[n].catch;break}null===r&&(r=-3),this.tryStack_.push({finally:t,finallyFallThrough:r})}null!==e&&this.tryStack_.push({catch:e})},popTry:function(){this.tryStack_.pop()},maybeUncatchable:function(){if(this.storedException===S)throw S},get sent(){return this.maybeThrow(),this.sent_},set sent(e){this.sent_=e},get sentIgnoreThrow(){return this.sent_},maybeThrow:function(){if("throw"===this.action)throw this.action="next",this.sent_},end:function(){switch(this.state){case-2:return this;case-3:throw this.storedException;default:throw t(this.state)}},handleException:function(e){throw this.GState=x,this.state=-2,e},wrapYieldStar:function(e){var t=this;return{next:function(t){return e.next(t)},throw:function(r){var n;if(r===S){if(e.return){if(!(n=e.return(t.returnValue)).done)return t.returnValue=t.oldReturnValue,n;t.returnValue=n.value}throw r}if(e.throw)return e.throw(r);throw e.return&&e.return(),p("Inner iterator does not have a throw method")}}}};var T=f(),A=f();return i.prototype=a,R(a,"constructor",e(i)),a.prototype={constructor:a,next:function(e){return n(h(this,T),h(this,A),"next",e)},throw:function(e){return n(h(this,T),h(this,A),"throw",e)},return:function(e){var t=h(this,T);return t.oldReturnValue=t.returnValue,t.returnValue=e,n(t,h(this,A),"throw",S)}},b(a.prototype,{constructor:{enumerable:!1},next:{enumerable:!1},throw:{enumerable:!1},return:{enumerable:!1}}),Object.defineProperty(a.prototype,Symbol.iterator,e(function(){return this})),s.prototype=y(r.prototype),s.prototype.end=function(){switch(this.state){case-2:this.resolve(this.returnValue);break;case-3:this.reject(this.storedException);break;default:this.reject(t(this.state))}},s.prototype.handleException=function(){this.state=-3},{get createGeneratorInstance(){return o},get initGeneratorFunction(){return u},get asyncWrap(){return c}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/asyncWrap.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./generators.js","[email protected]/src/runtime/modules/asyncWrap.js"));return{get default(){return e.asyncWrap}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/initGeneratorFunction.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./generators.js","[email protected]/src/runtime/modules/initGeneratorFunction.js"));return{get default(){return e.initGeneratorFunction}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/createGeneratorInstance.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./generators.js","[email protected]/src/runtime/modules/createGeneratorInstance.js"));return{get default(){return e.createGeneratorInstance}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/generators.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/asyncWrap.js","[email protected]/src/runtime/generators.js")).default,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/initGeneratorFunction.js","[email protected]/src/runtime/generators.js")).default,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/createGeneratorInstance.js","[email protected]/src/runtime/generators.js")).default;return $traceurRuntime.asyncWrap=e,$traceurRuntime.initGeneratorFunction=t,$traceurRuntime.createGeneratorInstance=r,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/spawn.js",[],function(){"use strict";function e(e,t,r){return new Promise(function(n,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function o(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){e.done?n(e.value):Promise.resolve(e.value).then(a,o)}u((r=r.apply(e,t)).next())})}return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/spawn.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/spawn.js","[email protected]/src/runtime/spawn.js")).default;return $traceurRuntime.spawn=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/getTemplateObject.js",[],function(){"use strict";function e(e){var t=arguments[1],o=e.join("${}"),u=a[o];return u||(t||(t=i.call(e)),a[o]=n(r(t,"raw",{value:n(e)})))}var t=Object,r=t.defineProperty,n=t.freeze,i=Array.prototype.slice,a=Object.create(null);return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/template.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/getTemplateObject.js","[email protected]/src/runtime/template.js")).default;return $traceurRuntime.getTemplateObject=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/modules/spreadProperties.js",[],function(){"use strict";function e(e,t,r){n(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0})}function t(t,r){if(null!=r){var n=function(n){for(var i=0;i<n.length;i++){var a=n[i];if(o.call(r,a)){var u=r[a];e(t,a,u)}}};n(i(r)),n(a(r))}}var r=Object,n=r.defineProperty,i=r.getOwnPropertyNames,a=r.getOwnPropertySymbols,o=r.propertyIsEnumerable,u=function(){for(var e=arguments[0],r=1;r<arguments.length;r++)t(e,arguments[r]);return e};return{get default(){return u}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/jsx.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./modules/spreadProperties.js","[email protected]/src/runtime/jsx.js")).default;return $traceurRuntime.spreadProperties=e,{}}),$traceurRuntime.registerModule("[email protected]/src/runtime/runtime-modules.js",[],function(){"use strict";return $traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./symbols.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./classes.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./exportStar.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./properTailCalls.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./relativeRequire.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./spread.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./destructuring.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./async.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./generators.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./spawn.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./template.js","[email protected]/src/runtime/runtime-modules.js")),$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./jsx.js","[email protected]/src/runtime/runtime-modules.js")),{}}),$traceurRuntime.getModule("[email protected]/src/runtime/runtime-modules.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/frozen-data.js",[],function(){"use strict";function e(e,t){for(var r=0;r<e.length;r+=2)if(e[r]===t)return r;return-1}function t(t,r,n){-1===e(t,r)&&t.push(r,n)}function r(t,r){var n=e(t,r);if(-1!==n)return t[n+1]}function n(t,r){return-1!==e(t,r)}function i(t,r){var n=e(t,r);return-1!==n&&(t.splice(n,2),!0)}return{get setFrozen(){return t},get getFrozen(){return r},get hasFrozen(){return n},get deleteFrozen(){return i}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/utils.js",[],function(){"use strict";function e(e){if(null==e)throw x();return S(e)}function t(e){return e>>>0}function r(e){return e&&("object"==typeof e||"function"==typeof e)}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function a(e){return e=+e,w(e)?0:0!==e&&R(e)?e>0?b(e):y(e):e}function o(e){var t=a(e);return t<0?0:_(t,T)}function u(e){return r(e)?e[Symbol.iterator]:void 0}function s(e){return n(e)}function c(e,t){return{value:e,done:t}}function l(e,t,r){t in e||Object.defineProperty(e,t,r)}function d(e,t,r){l(e,t,{value:r,configurable:!0,enumerable:!1,writable:!0})}function m(e,t,r){l(e,t,{value:r,configurable:!1,enumerable:!1,writable:!1})}function f(e,t){for(var r=0;r<t.length;r+=2)d(e,t[r],t[r+1])}function h(e,t){for(var r=0;r<t.length;r+=2)m(e,t[r],t[r+1])}function g(e,t,r){r&&r.iterator&&!e[r.iterator]&&(e["@@iterator"]&&(t=e["@@iterator"]),Object.defineProperty(e,r.iterator,{value:t,configurable:!0,enumerable:!1,writable:!0}))}function p(e){A.push(e)}function v(e){A.forEach(function(t){return t(e)})}var y=Math.ceil,b=Math.floor,R=isFinite,w=isNaN,M=Math.pow,_=Math.min,x=TypeError,S=Object,T=M(2,53)-1,A=[];return{get toObject(){return e},get toUint32(){return t},get isObject(){return r},get isCallable(){return n},get isNumber(){return i},get toInteger(){return a},get toLength(){return o},get checkIterable(){return u},get isConstructor(){return s},get createIteratorResultObject(){return c},get maybeDefine(){return l},get maybeDefineMethod(){return d},get maybeDefineConst(){return m},get maybeAddFunctions(){return f},get maybeAddConsts(){return h},get maybeAddIterator(){return g},get registerPolyfill(){return p},get polyfillAll(){return v}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Map.js",[],function(){"use strict";function e(e){return s(e,x)}function t(t){var r=e(t);return r||(r=_++,c(t,x,r)),r}function r(t,r){if("string"==typeof r)return t.stringIndex_[r];if(g(r)){if(!w(r))return m(t.frozenData_,r);var n=e(r);if(void 0===n)return;return t.objectIndex_[n]}return t.primitiveIndex_[r]}function n(e){e.entries_=[],e.objectIndex_=Object.create(null),e.stringIndex_=Object.create(null),e.primitiveIndex_=Object.create(null),e.frozenData_=[],e.deletedCount_=0}function i(e){var t=e,r=t.Map,n=t.Symbol;if(!(r&&v()&&r.prototype[n.iterator]&&r.prototype.entries))return!0;try{return 1!==new r([[]]).size}catch(e){return!1}}function a(e){i(e)&&(e.Map=S)}var o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/polyfills/Map.js")),u=o.createPrivateSymbol,s=o.getPrivate,c=o.setPrivate,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../frozen-data.js","[email protected]/src/runtime/polyfills/Map.js")),d=l.deleteFrozen,m=l.getFrozen,f=l.setFrozen,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Map.js")),g=h.isObject,p=h.registerPolyfill,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../has-native-symbols.js","[email protected]/src/runtime/polyfills/Map.js")).default,y=Object,b=y.defineProperty,R=(y.getOwnPropertyDescriptor,y.hasOwnProperty),w=y.isExtensible,M={},_=1,x=u(),S=function(){return $traceurRuntime.createClass(function(){var e,t,r=arguments[0];if(!g(this))throw new TypeError("Map called on incompatible type");if(R.call(this,"entries_"))throw new TypeError("Map can not be reentrantly initialised");if(n(this),null!==r&&void 0!==r){var i=!0,a=!1,o=void 0;try{for(var u=void 0,s=r[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=(e=u.value[Symbol.iterator](),(t=e.next()).done?void 0:t.value),l=(t=e.next()).done?void 0:t.value;this.set(c,l)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}}},{get size(){return this.entries_.length/2-this.deletedCount_},get:function(e){var t=r(this,e);if(void 0!==t)return this.entries_[t+1]},set:function(e,n){var i=r(this,e);if(void 0!==i)this.entries_[i+1]=n;else if(i=this.entries_.length,this.entries_[i]=e,this.entries_[i+1]=n,g(e))if(w(e)){var a=t(e);this.objectIndex_[a]=i}else f(this.frozenData_,e,i);else"string"==typeof e?this.stringIndex_[e]=i:this.primitiveIndex_[e]=i;return this},has:function(e){return void 0!==r(this,e)},delete:function(t){var n=r(this,t);if(void 0===n)return!1;if(this.entries_[n]=M,this.entries_[n+1]=void 0,this.deletedCount_++,g(t))if(w(t)){var i=e(t);delete this.objectIndex_[i]}else d(this.frozenData_,t);else"string"==typeof t?delete this.stringIndex_[t]:delete this.primitiveIndex_[t];return!0},clear:function(){n(this)},forEach:function(e){for(var t=arguments[1],r=0;r<this.entries_.length;r+=2){var n=this.entries_[r],i=this.entries_[r+1];n!==M&&e.call(t,i,n,this)}},entries:$traceurRuntime.initGeneratorFunction(function e(){var t,r,n;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=0,e.state=12;break;case 12:e.state=t<this.entries_.length?8:-2;break;case 4:t+=2,e.state=12;break;case 8:r=this.entries_[t],n=this.entries_[t+1],e.state=9;break;case 9:e.state=r===M?4:6;break;case 6:return e.state=2,[r,n];case 2:e.maybeThrow(),e.state=4;break;default:return e.end()}},e,this)}),keys:$traceurRuntime.initGeneratorFunction(function e(){var t,r,n;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=0,e.state=12;break;case 12:e.state=t<this.entries_.length?8:-2;break;case 4:t+=2,e.state=12;break;case 8:r=this.entries_[t],n=this.entries_[t+1],e.state=9;break;case 9:e.state=r===M?4:6;break;case 6:return e.state=2,r;case 2:e.maybeThrow(),e.state=4;break;default:return e.end()}},e,this)}),values:$traceurRuntime.initGeneratorFunction(function e(){var t,r,n;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=0,e.state=12;break;case 12:e.state=t<this.entries_.length?8:-2;break;case 4:t+=2,e.state=12;break;case 8:r=this.entries_[t],n=this.entries_[t+1],e.state=9;break;case 9:e.state=r===M?4:6;break;case 6:return e.state=2,n;case 2:e.maybeThrow(),e.state=4;break;default:return e.end()}},e,this)})},{})}();return b(S.prototype,Symbol.iterator,{configurable:!0,writable:!0,value:S.prototype.entries}),p(a),{get Map(){return S},get polyfillMap(){return a}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Map.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Set.js",[],function(){"use strict";function e(e){var t=e,r=t.Set,n=t.Symbol;if(!(r&&o()&&r.prototype[n.iterator]&&r.prototype.values))return!0;try{return 1!==new r([1]).size}catch(e){return!1}}function t(t){e(t)&&(t.Set=s)}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Set.js")),n=r.isObject,i=r.registerPolyfill,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./Map.js","[email protected]/src/runtime/polyfills/Set.js")).Map,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../has-native-symbols.js","[email protected]/src/runtime/polyfills/Set.js")).default,u=Object.prototype.hasOwnProperty,s=function(){return $traceurRuntime.createClass(function(){var e=arguments[0];if(!n(this))throw new TypeError("Set called on incompatible type");if(u.call(this,"map_"))throw new TypeError("Set can not be reentrantly initialised");if(this.map_=new a,null!==e&&void 0!==e){var t=!0,r=!1,i=void 0;try{for(var o=void 0,s=e[Symbol.iterator]();!(t=(o=s.next()).done);t=!0){var c=o.value;this.add(c)}}catch(e){r=!0,i=e}finally{try{t||null==s.return||s.return()}finally{if(r)throw i}}}},{get size(){return this.map_.size},has:function(e){return this.map_.has(e)},add:function(e){return this.map_.set(e,e),this},delete:function(e){return this.map_.delete(e)},clear:function(){return this.map_.clear()},forEach:function(e){var t=arguments[1],r=this;return this.map_.forEach(function(n,i){e.call(t,i,i,r)})},values:$traceurRuntime.initGeneratorFunction(function e(){var t,r;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=e.wrapYieldStar(this.map_.keys()[Symbol.iterator]()),e.sent=void 0,e.action="next",e.state=12;break;case 12:r=t[e.action](e.sentIgnoreThrow),e.state=9;break;case 9:e.state=r.done?3:2;break;case 3:e.sent=r.value,e.state=-2;break;case 2:return e.state=12,r.value;default:return e.end()}},e,this)}),entries:$traceurRuntime.initGeneratorFunction(function e(){var t,r;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=e.wrapYieldStar(this.map_.entries()[Symbol.iterator]()),e.sent=void 0,e.action="next",e.state=12;break;case 12:r=t[e.action](e.sentIgnoreThrow),e.state=9;break;case 9:e.state=r.done?3:2;break;case 3:e.sent=r.value,e.state=-2;break;case 2:return e.state=12,r.value;default:return e.end()}},e,this)})},{})}();return Object.defineProperty(s.prototype,Symbol.iterator,{configurable:!0,writable:!0,value:s.prototype.values}),Object.defineProperty(s.prototype,"keys",{configurable:!0,writable:!0,value:s.prototype.values}),i(t),{get Set(){return s},get polyfillSet(){return t}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Set.js"),$traceurRuntime.registerModule("[email protected]/node_modules/rsvp/lib/rsvp/asap.js",[],function(){"use strict";function e(e,t){m[o]=e,m[o+1]=t,2===(o+=2)&&a()}function t(){return function(){i(n)}}function r(){return function(){setTimeout(n,1)}}function n(){for(var e=0;e<o;e+=2)(0,m[e])(m[e+1]),m[e]=void 0,m[e+1]=void 0;o=0}var i,a,o=0,u="undefined"!=typeof window?window:void 0,s=u||{},c=s.MutationObserver||s.WebKitMutationObserver,l="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),d="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,m=new Array(1e3);return a=l?function(){var e=process.nextTick,t=process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);return Array.isArray(t)&&"0"===t[1]&&"10"===t[2]&&(e=setImmediate),function(){e(n)}}():c?function(){var e=0,t=new c(n),r=document.createTextNode("");return t.observe(r,{characterData:!0}),function(){r.data=e=++e%2}}():d?function(){var e=new MessageChannel;return e.port1.onmessage=n,function(){e.port2.postMessage(0)}}():void 0===u&&"function"==typeof require?function(){try{var e=require("vertx");return i=e.runOnLoop||e.runOnContext,t()}catch(e){return r()}}():r(),{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Promise.js",[],function(){"use strict";function e(e){return e&&"object"==typeof e&&void 0!==e.status_}function t(e){return e}function r(e){throw e}function n(e){var n=void 0!==arguments[1]?arguments[1]:t,a=void 0!==arguments[2]?arguments[2]:r,o=i(e.constructor);switch(e.status_){case void 0:throw TypeError;case 0:e.onResolve_.push(n,o),e.onReject_.push(a,o);break;case 1:l(e.value_,[n,o]);break;case-1:l(e.value_,[a,o])}return o.promise}function i(e){if(this===x){var t=o(new x(M));return{promise:t,resolve:function(e){u(t,e)},reject:function(e){s(t,e)}}}var r={};return r.promise=new e(function(e,t){r.resolve=e,r.reject=t}),r}function a(e,t,r,n,i){return e.status_=t,e.value_=r,e.onResolve_=n,e.onReject_=i,e}function o(e){return a(e,0,void 0,[],[])}function u(e,t){c(e,1,t,e.onResolve_)}function s(e,t){c(e,-1,t,e.onReject_)}function c(e,t,r,n){0===e.status_&&(l(r,n),a(e,t,r))}function l(e,t){h(function(){for(var r=0;r<t.length;r+=2)d(e,t[r],t[r+1])})}function d(t,r,i){try{var a=r(t);if(a===i.promise)throw new TypeError;e(a)?n(a,i.resolve,i.reject):i.resolve(a)}catch(e){try{i.reject(e)}catch(e){}}}function m(t,r){if(!e(r)&&p(r)){var n;try{n=r.then}catch(e){var a=S.call(t,e);return w(r,T,a),a}if("function"==typeof n){var o=R(r,T);if(o)return o;var u=i(t);w(r,T,u.promise);try{n.call(r,u.resolve,u.reject)}catch(e){u.reject(e)}return u.promise}}return r}function f(e){e.Promise||(e.Promise=_)}var h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../../../node_modules/rsvp/lib/rsvp/asap.js","[email protected]/src/runtime/polyfills/Promise.js")).default,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Promise.js")),p=g.isObject,v=g.registerPolyfill,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/polyfills/Promise.js")),b=y.createPrivateSymbol,R=y.getPrivate,w=y.setPrivate,M={},_=function(){return $traceurRuntime.createClass(function(e){if(e!==M){if("function"!=typeof e)throw new TypeError;var t=o(this);try{e(function(e){u(t,e)},function(e){s(t,e)})}catch(e){s(t,e)}}},{catch:function(e){return this.then(void 0,e)},then:function(i,a){"function"!=typeof i&&(i=t),"function"!=typeof a&&(a=r);var o=this,u=this.constructor;return n(this,function(t){return(t=m(u,t))===o?a(new TypeError):e(t)?t.then(i,a):i(t)},a)}},{resolve:function(t){return this===x?e(t)?t:a(new x(M),1,t):new this(function(e,r){e(t)})},reject:function(e){return this===x?a(new x(M),-1,e):new this(function(t,r){r(e)})},all:function(e){var t=i(this),r=[];try{var n=0,a=0,o=!0,u=!1,s=void 0;try{for(var c=void 0,l=e[Symbol.iterator]();!(o=(c=l.next()).done);o=!0){var d=c.value,m=function(e){return function(i){r[e]=i,0==--n&&t.resolve(r)}}(a);this.resolve(d).then(m,function(e){t.reject(e)}),++a,++n}}catch(e){u=!0,s=e}finally{try{o||null==l.return||l.return()}finally{if(u)throw s}}0===n&&t.resolve(r)}catch(e){t.reject(e)}return t.promise},race:function(e){var t=i(this);try{for(var r=0;r<e.length;r++)this.resolve(e[r]).then(function(e){t.resolve(e)},function(e){t.reject(e)})}catch(e){t.reject(e)}return t.promise}})}(),x=_,S=x.reject,T=b();return v(f),{get Promise(){return _},get polyfillPromise(){return f}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Promise.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/StringIterator.js",[],function(){"use strict";function e(e){var t=String(e),r=Object.create(u.prototype);return r[a]=t,r[o]=0,r}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/StringIterator.js")),r=t.createIteratorResultObject,n=t.isObject,i=Object.prototype.hasOwnProperty,a=Symbol("iteratedString"),o=Symbol("stringIteratorNextIndex"),u=function(){var e;return $traceurRuntime.createClass(function(){},(e={},Object.defineProperty(e,"next",{value:function(){var e=this;if(!n(e)||!i.call(e,a))throw new TypeError("this must be a StringIterator object");var t=e[a];if(void 0===t)return r(void 0,!0);var u=e[o],s=t.length;if(u>=s)return e[a]=void 0,r(void 0,!0);var c,l=t.charCodeAt(u);if(l<55296||l>56319||u+1===s)c=String.fromCharCode(l);else{var d=t.charCodeAt(u+1);c=d<56320||d>57343?String.fromCharCode(l):String.fromCharCode(l)+String.fromCharCode(d)}return e[o]=u+c.length,r(c,!1)},configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(e,Symbol.iterator,{value:function(){return this},configurable:!0,enumerable:!0,writable:!0}),e),{})}();return{get createStringIterator(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/String.js",[],function(){"use strict";function e(e){var t=String(this);if(null==this||"[object RegExp]"==g.call(e))throw TypeError();var r=t.length,n=String(e),i=(n.length,arguments.length>1?arguments[1]:void 0),a=i?Number(i):0;isNaN(a)&&(a=0);var o=Math.min(Math.max(a,0),r);return p.call(t,n,a)==o}function t(e){var t=String(this);if(null==this||"[object RegExp]"==g.call(e))throw TypeError();var r=t.length,n=String(e),i=n.length,a=r;if(arguments.length>1){var o=arguments[1];void 0!==o&&(a=o?Number(o):0,isNaN(a)&&(a=0))}var u=Math.min(Math.max(a,0),r)-i;return!(u<0)&&v.call(t,n,u)==u}function r(e){if(null==this)throw TypeError();var t=String(this);if(e&&"[object RegExp]"==g.call(e))throw TypeError();var r=t.length,n=String(e),i=n.length,a=arguments.length>1?arguments[1]:void 0,o=a?Number(a):0;return o!=o&&(o=0),!(i+Math.min(Math.max(o,0),r)>r)&&-1!=p.call(t,n,o)}function n(e){if(null==this)throw TypeError();var t=String(this),r=e?Number(e):0;if(isNaN(r)&&(r=0),r<0||r==1/0)throw RangeError();if(0==r)return"";for(var n="";r--;)n+=t;return n}function i(e){if(null==this)throw TypeError();var t=String(this),r=t.length,n=e?Number(e):0;if(isNaN(n)&&(n=0),!(n<0||n>=r)){var i,a=t.charCodeAt(n);return a>=55296&&a<=56319&&r>n+1&&(i=t.charCodeAt(n+1))>=56320&&i<=57343?1024*(a-55296)+i-56320+65536:a}}function a(e){var t=e.raw,r=t.length>>>0;if(0===r)return"";for(var n="",i=0;;){if(n+=t[i],i+1===r)return n;n+=arguments[++i]}}function o(e){var t,r,n=[],i=Math.floor,a=-1,o=arguments.length;if(!o)return"";for(;++a<o;){var u=Number(arguments[a]);if(!isFinite(u)||u<0||u>1114111||i(u)!=u)throw RangeError("Invalid code point: "+u);u<=65535?n.push(u):(t=55296+((u-=65536)>>10),r=u%1024+56320,n.push(t,r))}return String.fromCharCode.apply(null,n)}function u(){var e=c(this),t=String(e);return l(t)}function s(s){var c=s.String;m(c.prototype,["codePointAt",i,"endsWith",t,"includes",r,"repeat",n,"startsWith",e]),m(c,["fromCodePoint",o,"raw",a]),f(c.prototype,u,Symbol)}var c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../checkObjectCoercible.js","[email protected]/src/runtime/polyfills/String.js")).default,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./StringIterator.js","[email protected]/src/runtime/polyfills/String.js")).createStringIterator,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/String.js")),m=d.maybeAddFunctions,f=d.maybeAddIterator,h=d.registerPolyfill,g=Object.prototype.toString,p=String.prototype.indexOf,v=String.prototype.lastIndexOf;return h(s),{get startsWith(){return e},get endsWith(){return t},get includes(){return r},get repeat(){return n},get codePointAt(){return i},get raw(){return a},get fromCodePoint(){return o},get stringPrototypeIterator(){return u},get polyfillString(){return s}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/String.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/ArrayIterator.js",[],function(){"use strict";function e(e,t){var r=a(e),n=new d;return n.iteratorObject_=r,n.arrayIteratorNextIndex_=0,n.arrayIterationKind_=t,n}function t(){return e(this,l)}function r(){return e(this,s)}function n(){return e(this,c)}var i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/ArrayIterator.js")),a=i.toObject,o=i.toUint32,u=i.createIteratorResultObject,s=1,c=2,l=3,d=function(){var e;return $traceurRuntime.createClass(function(){},(e={},Object.defineProperty(e,"next",{value:function(){var e=a(this),t=e.iteratorObject_;if(!t)throw new TypeError("Object is not an ArrayIterator");var r=e.arrayIteratorNextIndex_,n=e.arrayIterationKind_;return r>=o(t.length)?(e.arrayIteratorNextIndex_=1/0,u(void 0,!0)):(e.arrayIteratorNextIndex_=r+1,n==c?u(t[r],!1):n==l?u([r,t[r]],!1):u(r,!1))},configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(e,Symbol.iterator,{value:function(){return this},configurable:!0,enumerable:!0,writable:!0}),e),{})}();return{get entries(){return t},get keys(){return r},get values(){return n}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Array.js",[],function(){"use strict";function e(e){var t,r,n=arguments[1],i=arguments[2],a=this,o=R(e),u=void 0!==n,s=0;if(u&&!f(n))throw TypeError();if(m(o)){t=h(a)?new a:[];var c=!0,l=!1,d=void 0;try{for(var g=void 0,p=o[Symbol.iterator]();!(c=(g=p.next()).done);c=!0){var v=g.value;t[s]=u?n.call(i,v,s):v,s++}}catch(e){l=!0,d=e}finally{try{c||null==p.return||p.return()}finally{if(l)throw d}}return t.length=s,t}for(r=b(o.length),t=h(a)?new a(r):new Array(r);s<r;s++)t[s]=u?void 0===i?n(o[s],s):n.call(i,o[s],s):o[s];return t.length=r,t}function t(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var r=this,n=e.length,i=h(r)?new r(n):new Array(n),a=0;a<n;a++)i[a]=e[a];return i.length=n,i}function r(e){var t=void 0!==arguments[1]?arguments[1]:0,r=arguments[2],n=R(this),i=b(n.length),a=y(t),o=void 0!==r?y(r):i;for(a=a<0?Math.max(i+a,0):Math.min(a,i),o=o<0?Math.max(i+o,0):Math.min(o,i);a<o;)n[a]=e,a++;return n}function n(e){return a(this,e,arguments[1])}function i(e){return a(this,e,arguments[1],!0)}function a(e,t){var r=arguments[2],n=void 0!==arguments[3]&&arguments[3],i=R(e),a=b(i.length);if(!f(t))throw TypeError();for(var o=0;o<a;o++){var u=i[o];if(t.call(r,u,o,i))return n?o:u}return n?-1:void 0}function o(a){var o=a,u=o.Array,d=o.Object,m=o.Symbol,f=l;m&&m.iterator&&u.prototype[m.iterator]&&(f=u.prototype[m.iterator]),g(u.prototype,["entries",s,"keys",c,"values",f,"fill",r,"find",n,"findIndex",i]),g(u,["from",e,"of",t]),p(u.prototype,f,m),p(d.getPrototypeOf([].values()),function(){return this},m)}var u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./ArrayIterator.js","[email protected]/src/runtime/polyfills/Array.js")),s=u.entries,c=u.keys,l=u.values,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Array.js")),m=d.checkIterable,f=d.isCallable,h=d.isConstructor,g=d.maybeAddFunctions,p=d.maybeAddIterator,v=d.registerPolyfill,y=d.toInteger,b=d.toLength,R=d.toObject;return v(o),{get from(){return e},get of(){return t},get fill(){return r},get find(){return n},get findIndex(){return i},get polyfillArray(){return o}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Array.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/assign.js",[],function(){"use strict";function e(e){for(var r=1;r<arguments.length;r++){var n=arguments[r],i=null==n?[]:t(n),a=void 0,o=i.length;for(a=0;a<o;a++){var u=i[a];e[u]=n[u]}}return e}var t=Object.keys;return{get default(){return e}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Object.js",[],function(){"use strict";function e(e,t){return e===t?0!==e||1/e==1/t:e!==e&&t!==t}function t(e,t){var r,n,i=l(t),a=i.length;for(r=0;r<a;r++){i[r];n=c(t,i[r]),s(e,i[r],n)}return e}function r(r){var n=r.Object;i(n,["assign",o,"is",e,"mixin",t])}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Object.js")),i=n.maybeAddFunctions,a=n.registerPolyfill,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./assign.js","[email protected]/src/runtime/polyfills/Object.js")).default,u=Object,s=u.defineProperty,c=u.getOwnPropertyDescriptor,l=u.getOwnPropertyNames;return a(r),{get assign(){return o},get is(){return e},get mixin(){return t},get polyfillObject(){return r}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Object.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Number.js",[],function(){"use strict";function e(e){return o(e)&&m(e)}function t(t){return e(t)&&l(t)===t}function r(e){return o(e)&&f(e)}function n(t){if(e(t)){var r=l(t);if(r===t)return d(r)<=h}return!1}function i(i){var a=i.Number;u(a,["MAX_SAFE_INTEGER",h,"MIN_SAFE_INTEGER",g,"EPSILON",p]),s(a,["isFinite",e,"isInteger",t,"isNaN",r,"isSafeInteger",n])}var a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Number.js")),o=a.isNumber,u=a.maybeAddConsts,s=a.maybeAddFunctions,c=a.registerPolyfill,l=a.toInteger,d=Math.abs,m=isFinite,f=isNaN,h=Math.pow(2,53)-1,g=1-Math.pow(2,53),p=Math.pow(2,-52);return c(i),{get MAX_SAFE_INTEGER(){return h},get MIN_SAFE_INTEGER(){return g},get EPSILON(){return p},get isFinite(){return e},get isInteger(){return t},get isNaN(){return r},get isSafeInteger(){return n},get polyfillNumber(){return i}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Number.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/fround.js",[],function(){"use strict";function e(e,t,r){function n(e){var t=l(e),r=e-t;return r<.5?t:r>.5?t+1:t%2?t+1:t}var i,a,o,u,h,g,p,v=(1<<t-1)-1;for(e!==e?(a=(1<<t)-1,o=f(2,r-1),i=0):e===1/0||e===-1/0?(a=(1<<t)-1,o=0,i=e<0?1:0):0===e?(a=0,o=0,i=1/e==-1/0?1:0):(i=e<0,(e=c(e))>=f(2,1-v)?(a=m(l(d(e)/s),1023),(o=n(e/f(2,a)*f(2,r)))/f(2,r)>=2&&(a+=1,o=1),a>v?(a=(1<<t)-1,o=0):(a+=v,o-=f(2,r))):(a=0,o=n(e/f(2,1-v-r)))),h=[],u=r;u;u-=1)h.push(o%2?1:0),o=l(o/2);for(u=t;u;u-=1)h.push(a%2?1:0),a=l(a/2);for(h.push(i?1:0),h.reverse(),g=h.join(""),p=[];g.length;)p.push(parseInt(g.substring(0,8),2)),g=g.substring(8);return p}function t(e,t,r){var n,i,a,o,u,s,c,l,d=[];for(n=e.length;n;n-=1)for(a=e[n-1],i=8;i;i-=1)d.push(a%2?1:0),a>>=1;return d.reverse(),o=d.join(""),u=(1<<t-1)-1,s=parseInt(o.substring(0,1),2)?-1:1,c=parseInt(o.substring(1,1+t),2),l=parseInt(o.substring(1+t),2),c===(1<<t)-1?0!==l?NaN:s*(1/0):c>0?s*f(2,c-u)*(1+l/f(2,r)):0!==l?s*f(2,-(u-1))*(l/f(2,r)):s<0?-0:0}function r(e){return t(e,8,23)}function n(t){return e(t,8,23)}function i(e){return 0===e||!a(e)||o(e)?e:r(n(Number(e)))}var a=isFinite,o=isNaN,u=Math,s=u.LN2,c=u.abs,l=u.floor,d=u.log,m=u.min,f=u.pow;return{get fround(){return i}}}),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/Math.js",[],function(){"use strict";function e(e){if(0==(e=_(+e)))return 32;var t=0;return 0==(4294901760&e)&&(e<<=16,t+=16),0==(4278190080&e)&&(e<<=8,t+=8),0==(4026531840&e)&&(e<<=4,t+=4),0==(3221225472&e)&&(e<<=2,t+=2),0==(2147483648&e)&&(e<<=1,t+=1),t}function t(e,t){var r=65535&(e=_(+e)),n=65535&(t=_(+t));return r*n+((e>>>16&65535)*n+r*(t>>>16&65535)<<16>>>0)|0}function r(e){return(e=+e)>0?1:e<0?-1:e}function n(e){return.4342944819032518*E(e)}function i(e){return 1.4426950408889634*E(e)}function a(e){if((e=+e)<-1||S(e))return NaN;if(0===e||e===1/0)return e;if(-1===e)return-1/0;var t=0;if(e<0||e>1)return E(1+e);for(var r=1;r<50;r++)r%2==0?t-=I(e,r)/r:t+=I(e,r)/r;return t}function o(e){return(e=+e)==-1/0?-1:x(e)&&0!==e?$(e)-1:e}function u(e){return 0==(e=+e)?1:S(e)?NaN:x(e)?(e<0&&(e=-e),e>21?$(e)/2:($(e)+$(-e))/2):1/0}function s(e){return e=+e,x(e)&&0!==e?($(e)-$(-e))/2:e}function c(e){if(0==(e=+e))return e;if(!x(e))return r(e);var t=$(e),n=$(-e);return(t-n)/(t+n)}function l(e){return(e=+e)<1?NaN:x(e)?E(e+G(e+1)*G(e-1)):e}function d(e){return 0!=(e=+e)&&x(e)?e>0?E(e+G(e*e+1)):-E(-e+G(e*e+1)):e}function m(e){return-1==(e=+e)?-1/0:1===e?1/0:0===e?e:S(e)||e<-1||e>1?NaN:.5*E((1+e)/(1-e))}function f(e,t){for(var r=arguments.length,n=new Array(r),i=0,a=0;a<r;a++){if((s=+(s=arguments[a]))===1/0||s===-1/0)return 1/0;(s=A(s))>i&&(i=s),n[a]=s}0===i&&(i=1);for(var o=0,u=0,a=0;a<r;a++){var s=n[a]/i,c=s*s-u,l=o+c;u=l-o-c,o=l}return G(o)*i}function h(e){return(e=+e)>0?j(e):e<0?C(e):e}function g(e){if(0==(e=+e))return e;var t=e<0;t&&(e=-e);var r=I(e,1/3);return t?-r:r}function p(p){var y=p.Math;w(y,["acosh",l,"asinh",d,"atanh",m,"cbrt",g,"clz32",e,"cosh",u,"expm1",o,"fround",v,"hypot",f,"imul",t,"log10",n,"log1p",a,"log2",i,"sign",r,"sinh",s,"tanh",c,"trunc",h])}var v,y,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./fround.js","[email protected]/src/runtime/polyfills/Math.js")).fround,R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/Math.js")),w=R.maybeAddFunctions,M=R.registerPolyfill,_=R.toUint32,x=isFinite,S=isNaN,T=Math,A=T.abs,C=T.ceil,$=T.exp,j=T.floor,E=T.log,I=T.pow,G=T.sqrt;return"function"==typeof Float32Array?(y=new Float32Array(1),v=function(e){return y[0]=Number(e),y[0]}):v=b,M(p),{get clz32(){return e},get imul(){return t},get sign(){return r},get log10(){return n},get log2(){return i},get log1p(){return a},get expm1(){return o},get cosh(){return u},get sinh(){return s},get tanh(){return c},get acosh(){return l},get asinh(){return d},get atanh(){return m},get hypot(){return f},get trunc(){return h},get fround(){return v},get cbrt(){return g},get polyfillMath(){return p}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/Math.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/WeakMap.js",[],function(){"use strict";function e(e){var t=e,r=t.WeakMap;t.Symbol;if(!r||!p())return!0;try{var n={};return new r([[n,!1]]).get(n)}catch(e){return!1}}function t(t){e(t)&&(t.WeakMap=R)}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/polyfills/WeakMap.js")),n=r.createPrivateSymbol,i=r.deletePrivate,a=r.getPrivate,o=r.hasPrivate,u=r.setPrivate,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../frozen-data.js","[email protected]/src/runtime/polyfills/WeakMap.js")),c=s.deleteFrozen,l=s.getFrozen,d=s.hasFrozen,m=s.setFrozen,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/WeakMap.js")),h=f.isObject,g=f.registerPolyfill,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../has-native-symbols.js","[email protected]/src/runtime/polyfills/WeakMap.js")).default,v=Object,y=(v.defineProperty,v.getOwnPropertyDescriptor,v.isExtensible),b=TypeError,R=(Object.prototype.hasOwnProperty,function(){return $traceurRuntime.createClass(function(){this.name_=n(),this.frozenData_=[]},{set:function(e,t){if(!h(e))throw new b("key must be an object");return y(e)?u(e,this.name_,t):m(this.frozenData_,e,t),this},get:function(e){if(h(e))return y(e)?a(e,this.name_):l(this.frozenData_,e)},delete:function(e){return!!h(e)&&(y(e)?i(e,this.name_):c(this.frozenData_,e))},has:function(e){return!!h(e)&&(y(e)?o(e,this.name_):d(this.frozenData_,e))}},{})}());return g(t),{get WeakMap(){return R},get polyfillWeakMap(){return t}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/WeakMap.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/WeakSet.js",[],function(){"use strict";function e(e){var t=e,r=t.WeakSet;t.Symbol;if(!r||!h())return!0;try{var n={};return!new r([[n]]).has(n)}catch(e){return!1}}function t(t){e(t)&&(t.WeakSet=y)}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../private.js","[email protected]/src/runtime/polyfills/WeakSet.js")),n=r.createPrivateSymbol,i=r.deletePrivate,a=(r.getPrivate,r.hasPrivate),o=r.setPrivate,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../frozen-data.js","[email protected]/src/runtime/polyfills/WeakSet.js")),s=u.deleteFrozen,c=u.getFrozen,l=u.setFrozen,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/WeakSet.js")),m=d.isObject,f=d.registerPolyfill,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("../has-native-symbols.js","[email protected]/src/runtime/polyfills/WeakSet.js")).default,g=Object,p=(g.defineProperty,g.isExtensible),v=TypeError,y=(Object.prototype.hasOwnProperty,function(){return $traceurRuntime.createClass(function(){this.name_=n(),this.frozenData_=[]},{add:function(e){if(!m(e))throw new v("value must be an object");return p(e)?o(e,this.name_,!0):l(this.frozenData_,e,e),this},delete:function(e){return!!m(e)&&(p(e)?i(e,this.name_):s(this.frozenData_,e))},has:function(e){return!!m(e)&&(p(e)?a(e,this.name_):c(this.frozenData_,e)===e)}},{})}());return f(t),{get WeakSet(){return y},get polyfillWeakSet(){return t}}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/WeakSet.js"),$traceurRuntime.registerModule("[email protected]/src/runtime/polyfills/polyfills.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("./utils.js","[email protected]/src/runtime/polyfills/polyfills.js")).polyfillAll;e(Reflect.global);var t=$traceurRuntime.setupGlobals;return $traceurRuntime.setupGlobals=function(r){t(r),e(r)},{}}),$traceurRuntime.getModule("[email protected]/src/runtime/polyfills/polyfills.js"),$traceurRuntime.registerModule("src/base/CooldownThrottle.js",[],function(){"use strict";var e=function(){return $traceurRuntime.createClass(function(e,t){var r=void 0!==arguments[2]?arguments[2]:0,n=void 0!==arguments[3]&&arguments[3];this.action=e,this.cooldownDuration=t,this.slowActionCooldownPumpupFactor=r,this._waitWithRequestAnimationFrame=n,this._state="idle",this._cooldownStartTime=-1/0},{_triggerIdle:function(){var e=this.cooldownDuration-(performance.now()-this._cooldownStartTime);if(e>0)this._forceIdleTriggerAfter(e);else{this._state="running";var t=performance.now();try{this.action()}finally{var r=performance.now()-t;this._cooldownStartTime=performance.now()+r*this.slowActionCooldownPumpupFactor,"running-and-triggered"===this._state?this._forceIdleTriggerAfter(this.cooldownDuration):this._state="idle"}}},trigger:function(){switch(this._state){case"idle":this._triggerIdle();break;case"waiting":break;case"running":this._state="running-and-triggered";break;case"running-and-triggered":break;default:throw new Error("Unrecognized throttle state: "+this._state)}},_forceIdleTriggerAfter:function(e){var t=this;if(this._state="waiting",this._waitWithRequestAnimationFrame){var r,n=performance.now();(r=function(){performance.now()<n+e?requestAnimationFrame(r):(t._state="idle",t._cooldownStartTime=-1/0,t.trigger())})()}else setTimeout(function(){t._state="idle",t._cooldownStartTime=-1/0,t.trigger()},e)}},{})}();return{get CooldownThrottle(){return e}}}),$traceurRuntime.registerModule("src/base/Describe.js",[],function(){"use strict";function e(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?'"'+e+'"':"number"==typeof e?""+e:void 0}function t(e,t){return 0===t?l:e instanceof Map?i(e,t):e instanceof Set?a(e,t):void 0!==e[Symbol.iterator]?o(e,t):void 0}function r(e,t){var r=String(e);return r!==c?r:u(e,t)}function n(n){var i=void 0!==arguments[1]?arguments[1]:d;return e(n)||t(n,i)||r(n,i)}function i(e,t){var r,i,a=[],o=!0,u=!1,c=void 0;try{for(var l=void 0,d=e.entries()[Symbol.iterator]();!(o=(l=d.next()).done);o=!0){var m=(r=l.value[Symbol.iterator](),(i=r.next()).done?void 0:i.value),f=(i=r.next()).done?void 0:i.value;if(a.length>s){a.push("[...]");break}var h=n(m,t-1),g=n(f,t-1);a.push(h+": "+g)}}catch(e){u=!0,c=e}finally{try{o||null==d.return||d.return()}finally{if(u)throw c}}return"Map{"+a.join(", ")+"}"}function a(e,t){var r=[],i=!0,a=!1,o=void 0;try{for(var u=void 0,c=e[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var l=u.value;if(r.length>s){r.push("[...]");break}r.push(n(l,t-1))}}catch(e){a=!0,o=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw o}}return"Set{"+r.join(", ")+"}"}function o(e,t){var r=[],i=!0,a=!1,o=void 0;try{for(var u=void 0,c=e[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var l=u.value;if(r.length>s){r.push("[...]");break}r.push(n(l,t-1))}}catch(e){a=!0,o=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw o}}return(Array.isArray(e)?"":e.constructor.name)+"["+r.join(", ")+"]"}function u(e,t){var r=[];for(var i in e)if(e.hasOwnProperty(i)){if(r.length>s){r.push("[...]");break}var a=e[i],o=n(i,t-1),u=n(a,t-1);r.push(o+": "+u)}var c=e.constructor.name;return(c==={}.constructor.name?"":"(Type: "+c+")")+"{"+r.join(", ")+"}"}var s=1e3,c=(new function(){}).toString(),l="!recursion-limit!",d=10;return{get describe(){return n}}}),$traceurRuntime.registerModule("src/base/DetailedError.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Describe.js","src/base/DetailedError.js")).describe,t=0,r=function(r){function n(r,i){$traceurRuntime.superConstructor(n).call(this,r),this.detailsObj=i,this.name="Error",this.message=r,this.stack=(new Error).stack,void 0!==this.stack&&(this.stack=this.stack.replace(/^Error\n\s+at new DetailedError (\S+)\s?\n\s+at /,"\n ")),t++;try{this.details=1===t?e(this.detailsObj):"(failed to describe detailsObj due to possibly re-entrancy)"}catch(e){console.error(e),this.details="(failed to describe detailsObj, see the console for details)"}finally{t--}}return $traceurRuntime.createClass(n,{toString:function(){return $traceurRuntime.superGet(this,n.prototype,"toString").call(this)+"\nDetails: "+this.details}},{},r)}(Error);return{get DetailedError(){return r}}}),$traceurRuntime.registerModule("src/base/Equate.js",[],function(){"use strict";function e(e,u){if(e===u||t(e)&&t(u))return!0;var l=r(e,u);return void 0!==l?l:!(n(e)||n(u)||!a(e,u))&&(e instanceof Map?s(e,u):e instanceof Set?c(e,u):i(e)?o(e,u):d(e,u))}function t(e){return"number"==typeof e&&isNaN(e)}function r(e,t){return!n(e)&&e.constructor.prototype.hasOwnProperty("isEqualTo")?e.isEqualTo(t):!n(t)&&t.constructor.prototype.hasOwnProperty("isEqualTo")?t.isEqualTo(e):void 0}function n(e){return null===e||void 0===e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e}function i(e){return Array.isArray(e)||!m.every(function(t){return!(e instanceof t)})}function a(e,t){return e.constructor.name===t.constructor.name}function o(t,r){if(t.length!==r.length)return!1;for(var n=0;n<t.length;n++)if(!e(t[n],r[n]))return!1;return!0}function u(t,r){var n=r[Symbol.iterator](),i=!0,a=!1,o=void 0;try{for(var u=void 0,s=t[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value,l=n.next();if(l.done||!e(c,l.value))return!1}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}return n.next().done}function s(t,r){var n,i;if(t.size!==r.size)return!1;var a=!0,o=!1,u=void 0;try{for(var s=void 0,c=t[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=(n=s.value[Symbol.iterator](),(i=n.next()).done?void 0:i.value),d=(i=n.next()).done?void 0:i.value;if(!r.has(l))return!1;if(!e(d,r.get(l)))return!1}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}return!0}function c(e,t){if(e.size!==t.size)return!1;var r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;if(!t.has(u))return!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return!0}function l(e){var t=new Set;for(var r in e)e.hasOwnProperty(r)&&t.add(r);return t}function d(t,r){var n=l(t);if(!c(n,l(r)))return!1;var i=!0,a=!1,o=void 0;try{for(var s=void 0,d=n[Symbol.iterator]();!(i=(s=d.next()).done);i=!0){var m=s.value;if(m!==Symbol.iterator&&!e(t[m],r[m]))return!1}}catch(e){a=!0,o=e}finally{try{i||null==d.return||d.return()}finally{if(a)throw o}}var f=void 0!==t[Symbol.iterator],h=void 0!==r[Symbol.iterator];return f===h&&!(f&&h&&!u(t,r))}var m=[Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint16Array,Uint32Array,Uint8ClampedArray];return{get equate(){return e}}}),$traceurRuntime.registerModule("src/base/Format.js",[],function(){"use strict";function e(t){var i=void 0!==arguments[1]?arguments[1]:0,a=arguments[2];if(Math.abs(t)<i)return"0";if(t<0)return"-"+e(-t,i,a);var o=n(r,function(e){return Math.abs(e.value-t)<=i});if(void 0!==o)return o.character;var u=n(r,function(e){return Math.abs(Math.sqrt(e.value)-t)<=i});return void 0!==u?"√"+u.character:t%1!=0&&void 0!==a?t.toFixed(a):t.toString()}var t=function(){function t(e,t,r,n){this.allowAbbreviation=e,this.maxAbbreviationError=t,this.fixedDigits=r,this.itemSeparator=n}return $traceurRuntime.createClass(t,{formatFloat:function(t){return this.allowAbbreviation?e(t,this.maxAbbreviationError,this.fixedDigits):void 0!==this.fixedDigits?t.toFixed(this.fixedDigits):t+""}},{parseFloat:function(e){if(0===e.length)throw new Error("Not a number: '"+e+"'");if("-"===e[0])return-t.parseFloat(e.substr(1));if("√"===e[0])return Math.sqrt(t.parseFloat(e.substr(1)));var i=n(r,function(t){return t.character===e});if(void 0!==i)return i.value;var a=parseFloat(e);if(isNaN(a))throw new Error("Not a number: '"+e+"'");return a},simplifyByRounding:function(e,i){if(e<0)return-t.simplifyByRounding(-e,i);var a=e%1;if(a<=i||1-a<=i)return Math.round(e);var o=n(r,function(t){return Math.abs(t.value-e)<=i});if(void 0!==o)return o.value;var u=n(r,function(t){return Math.abs(Math.sqrt(t.value)-e)<=i});return void 0!==u?Math.sqrt(u.value):e}})}(),r=[{character:"½",ref:"½",expanded:"1/2",value:.5},{character:"¼",ref:"¼",expanded:"1/4",value:.25},{character:"¾",ref:"¾",expanded:"3/4",value:.75},{character:"⅓",ref:"⅓",expanded:"1/3",value:1/3},{character:"⅔",ref:"⅔",expanded:"2/3",value:2/3},{character:"⅕",ref:"⅕",expanded:"1/5",value:.2},{character:"⅖",ref:"⅖",expanded:"2/5",value:.4},{character:"⅗",ref:"⅗",expanded:"3/5",value:.6},{character:"⅘",ref:"⅘",expanded:"4/5",value:.8},{character:"⅙",ref:"⅙",expanded:"1/6",value:1/6},{character:"⅚",ref:"⅚",expanded:"5/6",value:5/6},{character:"⅐",ref:"⅐",expanded:"1/7",value:1/7},{character:"⅛",ref:"⅛",expanded:"1/8",value:1/8},{character:"⅜",ref:"⅜",expanded:"3/8",value:3/8},{character:"⅝",ref:"⅝",expanded:"5/8",value:5/8},{character:"⅞",ref:"⅞",expanded:"7/8",value:7/8},{character:"⅑",ref:"⅑",expanded:"1/9",value:1/9},{character:"⅒",ref:"⅒",expanded:"1/10",value:.1}],n=function(e,t){var r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;if(t(u))return u}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}};return t.EXACT=new t(!0,0,void 0,", "),t.MINIFIED=new t(!0,0,void 0,","),t.SIMPLIFIED=new t(!0,5e-4,3,", "),t.CONSISTENT=new t(!1,0,2,", "),{get Format(){return t},get UNICODE_FRACTIONS(){return r}}}),$traceurRuntime.registerModule("src/base/Obs.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/CooldownThrottle.js","src/base/Obs.js")).CooldownThrottle,t=function(){function t(e){this._subscribe=e}return $traceurRuntime.createClass(t,{subscribe:function(e){return this._subscribe(e)},snapshot:function(){var e=[];return this.subscribe(function(t){return e.push(t)})(),e},map:function(e){var r=this;return new t(function(t){return r.subscribe(function(r){return t(e(r))})})},filter:function(e){var r=this;return new t(function(t){return r.subscribe(function(r){e(r)&&t(r)})})},zipLatest:function(e,r){var n=this;return new t(function(t){var i,a,o=!1,u=!1,s=n.subscribe(function(e){i=e,o=!0,u&&t(r(i,a))}),c=e.subscribe(function(e){a=e,u=!0,o&&t(r(i,a))});return function(){s(),c()}})},flattenLatest:function(){var e=this;return new t(function(t){var r=function(){},n=!1,i=e.subscribe(function(e){if(!n){var i=r;r=e.subscribe(t),i()}});return function(){n=!0,r(),i()}})},peek:function(e){return this.map(function(t){return e(t),t})},flatten:function(){var e=this;return new t(function(t){var r=[];return r.push(e.subscribe(function(e){return r.push(e.subscribe(t))})),function(){var e=!0,t=!1,n=void 0;try{for(var i=void 0,a=r[Symbol.iterator]();!(e=(i=a.next()).done);e=!0)(0,i.value)()}catch(e){t=!0,n=e}finally{try{e||null==a.return||a.return()}finally{if(t)throw n}}}})},throttleLatest:function(r){var n=this;return new t(function(t){var i=void 0,a=!1,o=new e(function(){a||t(i)},r),u=n.subscribe(function(e){i=e,o.trigger()});return function(){a=!0,u()}})},skip:function(e){var r=this;return new t(function(t){var n=e;return r.subscribe(function(e){n>0?n-=1:t(e)})})},whenDifferent:function(){var e=this,r=arguments[0]||function(e,t){return e===t};return new t(function(t){var n=!1,i=void 0;return e.subscribe(function(e){n&&r(i,e)||(i=e,n=!0,t(e))})})}},{of:function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return new t(function(t){var r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)t(a.value)}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return function(){}})},requestAnimationTicker:function(){return new t(function(e){var t,r=!1;return(t=function(){r||(e(void 0),window.requestAnimationFrame(t))})(),function(){r=!0}})},elementEvent:function(e,r){return new t(function(t){return e.addEventListener(r,t),function(){return e.removeEventListener(r,t)}})}})}(),r=function(){return $traceurRuntime.createClass(function(){var e=this;this._observers=[],this._observable=new t(function(t){e._observers.push(t);var r=!1;return function(){r||(r=!0,e._observers.splice(e._observers.indexOf(t),1))}})},{observable:function(){return this._observable},send:function(e){var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this._observers[Symbol.iterator]();!(t=(i=a.next()).done);t=!0)(0,i.value)(e)}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}},{})}(),n=function(){return $traceurRuntime.createClass(function(){var e=arguments[0],n=this;this._value=e,this._source=new r,this._observable=new t(function(e){return e(n._value),n._source.observable().subscribe(e)})},{observable:function(){return this._observable},set:function(e){this._value=e,this._source.send(e)},get:function(){return this._value}},{})}();return{get Observable(){return t},get ObservableSource(){return r},get ObservableValue(){return n}}}),$traceurRuntime.registerModule("src/base/RestartableRng.js",[],function(){"use strict";var e=function(){function e(){this._cache=[],this._next=0}return $traceurRuntime.createClass(e,{restarted:function(){var t=new e;return t._cache=this._cache,t},random:function(){var e=this._next++;return e>=this._cache.length&&this._cache.push(Math.random()),this._cache[e]}},{})}();return{get RestartableRng(){return e}}}),$traceurRuntime.registerModule("src/base/Revision.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Describe.js","src/base/Revision.js")).describe,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Equate.js","src/base/Revision.js")).equate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/base/Revision.js")).DetailedError,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/base/Revision.js")),i=n.ObservableSource,a=n.ObservableValue,o=function(){function n(e,t,n){if(t<0||t>=e.length)throw new r("Bad index",{history:e,index:t,isWorkingOnCommit:n});if(!Array.isArray(e))throw new r("Bad history",{history:e,index:t,isWorkingOnCommit:n});this.history=e,this.index=t,this.isWorkingOnCommit=n,this._changes=new i,this._latestActiveCommit=new a(this.history[this.index])}return $traceurRuntime.createClass(n,{changes:function(){return this._changes.observable()},latestActiveCommit:function(){return this._latestActiveCommit.observable()},peekActiveCommit:function(){return this._latestActiveCommit.get()},isAtBeginningOfHistory:function(){return 0===this.index&&!this.isWorkingOnCommit},isAtEndOfHistory:function(){return this.index===this.history.length-1},clear:function(e){this.history=[e],this.index=0,this.isWorkingOnCommit=!1,this._changes.send(e),this._latestActiveCommit.set(e)},startedWorkingOnCommit:function(){this.isWorkingOnCommit=!0,this._changes.send(void 0)},cancelCommitBeingWorkedOn:function(){this.isWorkingOnCommit=!1;var e=this.history[this.index];return this._changes.send(e),this._latestActiveCommit.set(e),e},commit:function(e){e!==this.history[this.index]?(this.isWorkingOnCommit=!1,this.index+=1,this.history.splice(this.index,this.history.length-this.index),this.history.push(e),this._changes.send(e),this._latestActiveCommit.set(e)):this.cancelCommitBeingWorkedOn()},undo:function(){if(!this.isWorkingOnCommit){if(0===this.index)return;this.index-=1}this.isWorkingOnCommit=!1;var e=this.history[this.index];return this._changes.send(e),this._latestActiveCommit.set(e),e},redo:function(){if(this.index+1!==this.history.length){this.index+=1,this.isWorkingOnCommit=!1;var e=this.history[this.index];return this._changes.send(e),this._latestActiveCommit.set(e),e}},toString:function(){return"Revision("+e({index:this.index,count:this.history.length,workingOnCommit:this.isWorkingOnCommit,head:this.history[this.index]})+")"},isEqualTo:function(e){return e instanceof n&&this.index===e.index&&this.isWorkingOnCommit===e.isWorkingOnCommit&&t(this.history,e.history)}},{startingAt:function(e){return new n([e],0,!1)}})}();return{get Revision(){return o}}}),$traceurRuntime.registerModule("src/base/Seq.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/base/Seq.js")).DetailedError,t={if_same_instance_as_this_then_throw:!0},r={not_a_normal_value:!0},n=[Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint16Array,Uint32Array,Uint8ClampedArray],i=function(e){return"function"==typeof Object(e)[Symbol.iterator]},a=function(e,n,i){if(e!==r)return e;if(n===t)throw new Error(i);return n},o=function(){function o(e){var t,r,n,a=void 0!==arguments[1]&&arguments[1];if(e instanceof o)r=e._iterable,n=e[Symbol.iterator];else if(a)t={},Object.defineProperty(t,Symbol.iterator,{value:e,configurable:!0,enumerable:!0,writable:!0}),r=t,n=e;else{if(!i(e))throw new Error("Not iterable: "+e);r=e,n=e[Symbol.iterator].bind(e)}this._iterable=r,this[Symbol.iterator]=n}return $traceurRuntime.createClass(o,{isEqualTo:function(e){var t=void 0!==arguments[1]?arguments[1]:function(e,t){return e===t};if(!i(e))return!1;if(e===this)return!0;var r=e[Symbol.iterator](),n=!0,a=!1,o=void 0;try{for(var u=void 0,s=this._iterable[Symbol.iterator]();!(n=(u=s.next()).done);n=!0){var c=u.value,l=r.next();if(l.done||!t(c,l.value))return!1}}catch(e){a=!0,o=e}finally{try{n||null==s.return||s.return()}finally{if(a)throw o}}return r.next().done},toArray:function(){return Array.from(this._iterable)},toFloat32Array:function(){var e=this.tryPeekCount();if(void 0===e)return new Float32Array(this.toArray());var t=new Float32Array(e),r=0,n=!0,i=!1,a=void 0;try{for(var o=void 0,u=this._iterable[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;t[r++]=s}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}return t},toSet:function(){return new Set(this._iterable)},join:function(e){return this.toArray().join(e)},toString:function(){return"Seq["+this.join(", ")+"]"},solidify:function(){var e=[Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint16Array,Uint32Array];if(Array.isArray(this._iterable))return this;var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var u=i.value;if(this._iterable instanceof u)return this}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}return new o(this.toArray())},map:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=!0,i=!1,a=void 0,r.state=24;break;case 24:r.pushTry(10,11),r.state=13;break;case 13:o=void 0,u=t[Symbol.iterator](),r.state=9;break;case 9:r.state=(n=(o=u.next()).done)?7:5;break;case 4:n=!0,r.state=9;break;case 5:s=o.value,r.state=6;break;case 6:return r.state=2,e(s);case 2:r.maybeThrow(),r.state=4;break;case 7:r.popTry(),r.state=11,r.finallyFallThrough=-2;break;case 10:r.popTry(),r.maybeUncatchable(),c=r.storedException,r.state=16;break;case 16:i=!0,a=c,r.state=11,r.finallyFallThrough=-2;break;case 11:r.popTry(),r.state=22;break;case 22:try{n||null==u.return||u.return()}finally{if(i)throw a}r.state=20;break;case 20:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},mapWithIndex:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=0,i=!0,a=!1,o=void 0,r.state=26;break;case 26:r.pushTry(12,13),r.state=15;break;case 15:u=void 0,s=t[Symbol.iterator](),r.state=11;break;case 11:r.state=(i=(u=s.next()).done)?9:7;break;case 6:i=!0,r.state=11;break;case 7:c=u.value,r.state=8;break;case 8:return r.state=2,e(c,n);case 2:r.maybeThrow(),r.state=4;break;case 4:n+=1,r.state=6;break;case 9:r.popTry(),r.state=13,r.finallyFallThrough=-2;break;case 12:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=18;break;case 18:a=!0,o=l,r.state=13,r.finallyFallThrough=-2;break;case 13:r.popTry(),r.state=24;break;case 24:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=22;break;case 22:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},flatMap:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=!0,i=!1,a=void 0,r.state=32;break;case 32:r.pushTry(18,19),r.state=21;break;case 21:o=void 0,u=t[Symbol.iterator](),r.state=17;break;case 17:r.state=(n=(o=u.next()).done)?15:13;break;case 10:n=!0,r.state=17;break;case 13:s=o.value,r.state=14;break;case 14:c=r.wrapYieldStar(e(s)[Symbol.iterator]()),r.sent=void 0,r.action="next",r.state=12;break;case 12:l=c[r.action](r.sentIgnoreThrow),r.state=9;break;case 9:r.state=l.done?3:2;break;case 3:r.sent=l.value,r.state=10;break;case 2:return r.state=12,l.value;case 15:r.popTry(),r.state=19,r.finallyFallThrough=-2;break;case 18:r.popTry(),r.maybeUncatchable(),d=r.storedException,r.state=24;break;case 24:i=!0,a=d,r.state=19,r.finallyFallThrough=-2;break;case 19:r.popTry(),r.state=30;break;case 30:try{n||null==u.return||u.return()}finally{if(i)throw a}r.state=28;break;case 28:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},filter:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=!0,i=!1,a=void 0,r.state=25;break;case 25:r.pushTry(11,12),r.state=14;break;case 14:o=void 0,u=t[Symbol.iterator](),r.state=10;break;case 10:r.state=(n=(o=u.next()).done)?8:6;break;case 4:n=!0,r.state=10;break;case 6:s=o.value,r.state=7;break;case 7:r.state=e(s)?1:4;break;case 1:return r.state=2,s;case 2:r.maybeThrow(),r.state=4;break;case 8:r.popTry(),r.state=12,r.finallyFallThrough=-2;break;case 11:r.popTry(),r.maybeUncatchable(),c=r.storedException,r.state=17;break;case 17:i=!0,a=c,r.state=12,r.finallyFallThrough=-2;break;case 12:r.popTry(),r.state=23;break;case 23:try{n||null==u.return||u.return()}finally{if(i)throw a}r.state=21;break;case 21:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},filterWithIndex:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=0,i=!0,a=!1,o=void 0,r.state=27;break;case 27:r.pushTry(13,14),r.state=16;break;case 16:u=void 0,s=t[Symbol.iterator](),r.state=12;break;case 12:r.state=(i=(u=s.next()).done)?10:8;break;case 7:i=!0,r.state=12;break;case 8:c=u.value,r.state=9;break;case 9:r.state=e(c,n)?1:4;break;case 1:return r.state=2,c;case 2:r.maybeThrow(),r.state=4;break;case 4:n++,r.state=7;break;case 10:r.popTry(),r.state=14,r.finallyFallThrough=-2;break;case 13:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=19;break;case 19:a=!0,o=l,r.state=14,r.finallyFallThrough=-2;break;case 14:r.popTry(),r.state=25;break;case 25:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=23;break;case 23:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},fold:function(e){var n=void 0!==arguments[1]?arguments[1]:t,i=r,o=!0,u=!1,s=void 0;try{for(var c=void 0,l=this._iterable[Symbol.iterator]();!(o=(c=l.next()).done);o=!0){var d=c.value;i=i===r?d:e(i,d)}}catch(e){u=!0,s=e}finally{try{o||null==l.return||l.return()}finally{if(u)throw s}}return a(i,n,"Folded empty sequence without providing an alternative result.")},aggregate:function(e,t){var r=e,n=!0,i=!1,a=void 0;try{for(var o=void 0,u=this._iterable[Symbol.iterator]();!(n=(o=u.next()).done);n=!0)r=t(r,o.value)}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}return r},zip:function(e,t){var r=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d,m;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:i=e[Symbol.iterator](),a=!0,o=!1,u=void 0,n.state=29;break;case 29:n.pushTry(15,16),n.state=18;break;case 18:s=void 0,c=r[Symbol.iterator](),n.state=14;break;case 14:n.state=(a=(s=c.next()).done)?12:10;break;case 7:a=!0,n.state=14;break;case 10:l=s.value,n.state=11;break;case 11:d=i.next(),n.state=9;break;case 9:n.state=d.done?12:2;break;case 2:return n.state=5,t(l,d.value);case 5:n.maybeThrow(),n.state=7;break;case 12:n.popTry(),n.state=16,n.finallyFallThrough=-2;break;case 15:n.popTry(),n.maybeUncatchable(),m=n.storedException,n.state=21;break;case 21:o=!0,u=m,n.state=16,n.finallyFallThrough=-2;break;case 16:n.popTry(),n.state=27;break;case 27:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=25;break;case 25:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},max:function(){var e=void 0!==arguments[0]?arguments[0]:t;return this.fold(function(e,t){return e<t?t:e},e)},min:function(){var e=void 0!==arguments[0]?arguments[0]:t;return this.fold(function(e,t){return e<t?e:t},e)},maxBy:function(e){var n=void 0!==arguments[1]?arguments[1]:t,i=void 0!==arguments[2]?arguments[2]:function(e,t){return e<t},o=r,u=r,s=!0,c=!1,l=void 0;try{for(var d=void 0,m=this._iterable[Symbol.iterator]();!(s=(d=m.next()).done);s=!0){var f=d.value;if(o!==r){u===r&&(u=e(o));var h=e(f);i(u,h)&&(o=f,u=h)}else o=f}}catch(e){c=!0,l=e}finally{try{s||null==m.return||m.return()}finally{if(c)throw l}}return a(o,n,"Can't maxBy an empty sequence.")},minBy:function(e){var r=void 0!==arguments[1]?arguments[1]:t,n=void 0!==arguments[2]?arguments[2]:function(e,t){return e<t};return this.maxBy(e,r,function(e,t){return n(t,e)})},any:function(e){var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this._iterable[Symbol.iterator]();!(t=(i=a.next()).done);t=!0)if(e(i.value))return!0}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}return!1},every:function(e){return!this.any(function(t){return!e(t)})},contains:function(e){return this.any(function(t){return t===e})},sum:function(){var e=0,t=!0,r=!0,n=!1,i=void 0;try{for(var a=void 0,o=this._iterable[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;e=t?u:e+u,t=!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return e},product:function(){return this.fold(function(e,t){return e*t},1)},scan:function(e,t){var r=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:i=e,n.state=30;break;case 30:return n.state=2,i;case 2:n.maybeThrow(),n.state=4;break;case 4:a=!0,o=!1,u=void 0,n.state=32;break;case 32:n.pushTry(16,17),n.state=19;break;case 19:s=void 0,c=r[Symbol.iterator](),n.state=15;break;case 15:n.state=(a=(s=c.next()).done)?13:11;break;case 8:a=!0,n.state=15;break;case 11:l=s.value,n.state=12;break;case 12:i=t(i,l),n.state=10;break;case 10:return n.state=6,i;case 6:n.maybeThrow(),n.state=8;break;case 13:n.popTry(),n.state=17,n.finallyFallThrough=-2;break;case 16:n.popTry(),n.maybeUncatchable(),d=n.storedException,n.state=22;break;case 22:o=!0,u=d,n.state=17,n.finallyFallThrough=-2;break;case 17:n.popTry(),n.state=28;break;case 28:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=26;break;case 26:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},reverse:function(){return new o(this.toArray().reverse())},flatten:function(){var e=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function t(){var r,n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(t){for(;;)switch(t.state){case 0:r=!0,n=!1,i=void 0,t.state=32;break;case 32:t.pushTry(18,19),t.state=21;break;case 21:a=void 0,o=e[Symbol.iterator](),t.state=17;break;case 17:t.state=(r=(a=o.next()).done)?15:13;break;case 10:r=!0,t.state=17;break;case 13:u=a.value,t.state=14;break;case 14:s=t.wrapYieldStar(u[Symbol.iterator]()),t.sent=void 0,t.action="next",t.state=12;break;case 12:c=s[t.action](t.sentIgnoreThrow),t.state=9;break;case 9:t.state=c.done?3:2;break;case 3:t.sent=c.value,t.state=10;break;case 2:return t.state=12,c.value;case 15:t.popTry(),t.state=19,t.finallyFallThrough=-2;break;case 18:t.popTry(),t.maybeUncatchable(),l=t.storedException,t.state=24;break;case 24:n=!0,i=l,t.state=19,t.finallyFallThrough=-2;break;case 19:t.popTry(),t.state=30;break;case 30:try{r||null==o.return||o.return()}finally{if(n)throw i}t.state=28;break;case 28:t.state=t.finallyFallThrough;break;default:return t.end()}},t,this)}))},concat:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=r.wrapYieldStar(t[Symbol.iterator]()),r.sent=void 0,r.action="next",r.state=12;break;case 12:i=n[r.action](r.sentIgnoreThrow),r.state=9;break;case 9:r.state=i.done?3:2;break;case 3:r.sent=i.value,r.state=10;break;case 2:return r.state=12,i.value;case 10:a=r.wrapYieldStar(e[Symbol.iterator]()),r.sent=void 0,r.action="next",r.state=24;break;case 24:o=a[r.action](r.sentIgnoreThrow),r.state=21;break;case 21:r.state=o.done?15:14;break;case 15:r.sent=o.value,r.state=-2;break;case 14:return r.state=24,o.value;default:return r.end()}},r,this)}))},withOverlayedItem:function(e,t){if(e<0)throw new Error("needed index >= 0");var r=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:if(void 0!==r.tryPeekCount()&&e>=r.tryPeekCount())throw new Error("needed index <= count");i=0,a=!0,o=!1,u=void 0,n.state=26;break;case 26:n.pushTry(12,13),n.state=15;break;case 15:s=void 0,c=r._iterable[Symbol.iterator](),n.state=11;break;case 11:n.state=(a=(s=c.next()).done)?9:7;break;case 6:a=!0,n.state=11;break;case 7:l=s.value,n.state=8;break;case 8:return n.state=2,i===e?t:l;case 2:n.maybeThrow(),n.state=4;break;case 4:i++,n.state=6;break;case 9:n.popTry(),n.state=13,n.finallyFallThrough=17;break;case 12:n.popTry(),n.maybeUncatchable(),d=n.storedException,n.state=18;break;case 18:o=!0,u=d,n.state=13,n.finallyFallThrough=17;break;case 13:n.popTry(),n.state=24;break;case 24:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=22;break;case 17:if(i<=e)throw new Error("sequence ended before overlay [withOverlayedItem(${index}, ${overlayedItem})]");n.state=-2;break;case 22:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},withTransformedItem:function(e,t){if(e<0)throw new Error("needed index >= 0");var r=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:if(void 0!==r.tryPeekCount()&&e>=r.tryPeekCount())throw new Error("needed index <= count");i=0,a=!0,o=!1,u=void 0,n.state=26;break;case 26:n.pushTry(12,13),n.state=15;break;case 15:s=void 0,c=r._iterable[Symbol.iterator](),n.state=11;break;case 11:n.state=(a=(s=c.next()).done)?9:7;break;case 6:a=!0,n.state=11;break;case 7:l=s.value,n.state=8;break;case 8:return n.state=2,i===e?t(l):l;case 2:n.maybeThrow(),n.state=4;break;case 4:i++,n.state=6;break;case 9:n.popTry(),n.state=13,n.finallyFallThrough=17;break;case 12:n.popTry(),n.maybeUncatchable(),d=n.storedException,n.state=18;break;case 18:o=!0,u=d,n.state=13,n.finallyFallThrough=17;break;case 13:n.popTry(),n.state=24;break;case 24:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=22;break;case 17:if(i<=e)throw new Error("sequence ended before transformation [withTransformedItem(${index}, ${itemTransformation})]");n.state=-2;break;case 22:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},withInsertedItem:function(e,t){if(e<0)throw new Error("needed index >= 0");var r=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:if(void 0!==r.tryPeekCount()&&e>r.tryPeekCount())throw new Error("needed index <= count");i=0,a=!0,o=!1,u=void 0,n.state=36;break;case 36:n.pushTry(17,18),n.state=20;break;case 20:s=void 0,c=r._iterable[Symbol.iterator](),n.state=16;break;case 16:n.state=(a=(s=c.next()).done)?14:12;break;case 9:a=!0,n.state=16;break;case 12:l=s.value,n.state=13;break;case 13:n.state=i===e?1:4;break;case 1:return n.state=2,t;case 2:n.maybeThrow(),n.state=4;break;case 4:i++,n.state=11;break;case 11:return n.state=7,l;case 7:n.maybeThrow(),n.state=9;break;case 14:n.popTry(),n.state=18,n.finallyFallThrough=22;break;case 17:n.popTry(),n.maybeUncatchable(),d=n.storedException,n.state=23;break;case 23:o=!0,u=d,n.state=18,n.finallyFallThrough=22;break;case 18:n.popTry(),n.state=29;break;case 29:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=27;break;case 22:n.state=i===e?30:33;break;case 30:return n.state=31,t;case 31:n.maybeThrow(),n.state=33;break;case 33:if(i<e)throw new Error("sequence ended before insertion [withInsertedItem(${index}, ${item})]");n.state=-2;break;case 27:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},takeWhile:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=!0,i=!1,a=void 0,r.state=27;break;case 27:r.pushTry(13,14),r.state=16;break;case 16:o=void 0,u=t[Symbol.iterator](),r.state=12;break;case 12:r.state=(n=(o=u.next()).done)?10:8;break;case 7:n=!0,r.state=12;break;case 8:s=o.value,r.state=9;break;case 9:r.state=e(s)?2:10;break;case 2:return r.state=5,s;case 5:r.maybeThrow(),r.state=7;break;case 10:r.popTry(),r.state=14,r.finallyFallThrough=-2;break;case 13:r.popTry(),r.maybeUncatchable(),c=r.storedException,r.state=19;break;case 19:i=!0,a=c,r.state=14,r.finallyFallThrough=-2;break;case 14:r.popTry(),r.state=25;break;case 25:try{n||null==u.return||u.return()}finally{if(i)throw a}r.state=23;break;case 23:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},skipTailWhile:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l,d,m;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=[],i=!0,a=!1,o=void 0,r.state=41;break;case 41:r.pushTry(27,28),r.state=30;break;case 30:u=void 0,s=t[Symbol.iterator](),r.state=26;break;case 26:r.state=(i=(u=s.next()).done)?24:22;break;case 20:i=!0,r.state=26;break;case 22:c=u.value,r.state=23;break;case 23:r.state=e(c)?19:11;break;case 19:n.push(c),r.state=20;break;case 11:l=r.wrapYieldStar(n[Symbol.iterator]()),r.sent=void 0,r.action="next",r.state=12;break;case 12:d=l[r.action](r.sentIgnoreThrow),r.state=9;break;case 9:r.state=d.done?3:2;break;case 3:r.sent=d.value,r.state=10;break;case 2:return r.state=12,d.value;case 10:n=[],r.state=18;break;case 18:return r.state=14,c;case 14:r.maybeThrow(),r.state=20;break;case 24:r.popTry(),r.state=28,r.finallyFallThrough=-2;break;case 27:r.popTry(),r.maybeUncatchable(),m=r.storedException,r.state=33;break;case 33:a=!0,o=m,r.state=28,r.finallyFallThrough=-2;break;case 28:r.popTry(),r.state=39;break;case 39:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=37;break;case 37:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},skipWhile:function(e){var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=!0,i=!0,a=!1,o=void 0,r.state=27;break;case 27:r.pushTry(13,14),r.state=16;break;case 16:u=void 0,s=t[Symbol.iterator](),r.state=12;break;case 12:r.state=(i=(u=s.next()).done)?10:8;break;case 4:i=!0,r.state=12;break;case 8:c=u.value,r.state=9;break;case 9:n=n&&e(c),r.state=7;break;case 7:r.state=n?4:1;break;case 1:return r.state=2,c;case 2:r.maybeThrow(),r.state=4;break;case 10:r.popTry(),r.state=14,r.finallyFallThrough=-2;break;case 13:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=19;break;case 19:a=!0,o=l,r.state=14,r.finallyFallThrough=-2;break;case 14:r.popTry(),r.state=25;break;case 25:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=23;break;case 23:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},take:function(e){if(e<0)throw new Error("needed maxTakeCount >= 0");if(0===e)return new o([]);var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=0,i=!0,a=!1,o=void 0,r.state=29;break;case 29:r.pushTry(15,16),r.state=18;break;case 18:u=void 0,s=t[Symbol.iterator](),r.state=14;break;case 14:r.state=(i=(u=s.next()).done)?12:10;break;case 6:i=!0,r.state=14;break;case 10:c=u.value,r.state=11;break;case 11:return r.state=2,c;case 2:r.maybeThrow(),r.state=4;break;case 4:n++,r.state=9;break;case 9:r.state=n>=e?12:6;break;case 12:r.popTry(),r.state=16,r.finallyFallThrough=-2;break;case 15:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=21;break;case 21:a=!0,o=l,r.state=16,r.finallyFallThrough=-2;break;case 16:r.popTry(),r.state=27;break;case 27:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=25;break;case 25:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},skip:function(e){if(e<0)throw new Error("needed maxSkipCount >= 0");if(0===e)return this;var t=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=0,i=!0,a=!1,o=void 0,r.state=27;break;case 27:r.pushTry(13,14),r.state=16;break;case 16:u=void 0,s=t[Symbol.iterator](),r.state=12;break;case 12:r.state=(i=(u=s.next()).done)?10:8;break;case 7:i=!0,r.state=12;break;case 8:c=u.value,r.state=9;break;case 9:r.state=n>=e?1:4;break;case 1:return r.state=2,c;case 2:r.maybeThrow(),r.state=4;break;case 4:n++,r.state=7;break;case 10:r.popTry(),r.state=14,r.finallyFallThrough=-2;break;case 13:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=19;break;case 19:a=!0,o=l,r.state=14,r.finallyFallThrough=-2;break;case 14:r.popTry(),r.state=25;break;case 25:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=23;break;case 23:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},distinctBy:function(e){var t=this;return o.fromGenerator(function(){var r=new Set;return t.filter(function(t){var n=e(t);return!r.has(n)&&(r.add(n),!0)})[Symbol.iterator]()})},distinct:function(){return this.distinctBy(function(e){return e})},segmentBy:function(e){var t=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l,d,m;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=[],i=void 0,a=!0,o=!1,u=void 0,r.state=36;break;case 36:r.pushTry(17,18),r.state=20;break;case 20:s=void 0,c=t[Symbol.iterator](),r.state=16;break;case 16:r.state=(a=(s=c.next()).done)?14:12;break;case 11:a=!0,r.state=16;break;case 12:l=s.value,r.state=13;break;case 13:d=e(l),r.state=9;break;case 9:r.state=n.length>0&&d!==i?1:6;break;case 1:return r.state=2,n;case 2:r.maybeThrow(),r.state=4;break;case 4:n=[],r.state=6;break;case 6:n.push(l),i=d,r.state=11;break;case 14:r.popTry(),r.state=18,r.finallyFallThrough=22;break;case 17:r.popTry(),r.maybeUncatchable(),m=r.storedException,r.state=23;break;case 23:o=!0,u=m,r.state=18,r.finallyFallThrough=22;break;case 18:r.popTry(),r.state=29;break;case 29:try{a||null==c.return||c.return()}finally{if(o)throw u}r.state=27;break;case 22:r.state=n.length>0?30:-2;break;case 30:return r.state=31,n;case 31:r.maybeThrow(),r.state=-2;break;case 27:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},single:function(){var e=void 0!==arguments[0]?arguments[0]:t,r=this[Symbol.iterator](),n=r.next();if(!n.done&&r.next().done)return n.value;if(e===t)throw n.done?new Error("Empty sequence doesn't contain a single item."):new Error("Sequence contains more than a single item.");return e},first:function(){var e=void 0!==arguments[0]?arguments[0]:t,r=this[Symbol.iterator]().next();if(!r.done)return r.value;if(e===t)throw new Error("Empty sequence has no first item.");return e},last:function(){var e=void 0!==arguments[0]?arguments[0]:t,n=r,i=!0,o=!1,u=void 0;try{for(var s=void 0,c=this._iterable[Symbol.iterator]();!(i=(s=c.next()).done);i=!0)n=s.value}catch(e){o=!0,u=e}finally{try{i||null==c.return||c.return()}finally{if(o)throw u}}return a(n,e,"Empty sequence has no last item.")},tryPeekCount:function(){var e=this;return Array.isArray(this._iterable)||!n.every(function(t){return!(e._iterable instanceof t)})?this._iterable.length:this._iterable instanceof Map||this._iterable instanceof Set?this._iterable.size:void 0},count:function(){var e=this.tryPeekCount();if(void 0!==e)return e;var t=0,r=!0,n=!1,i=void 0;try{for(var a=void 0,o=this._iterable[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){a.value;t++}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return t},padded:function(e){var t=arguments[1];if(e<0)throw new Error("needed minCount >= 0");var r=this._iterable;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:i=e,a=!0,o=!1,u=void 0,n.state=33;break;case 33:n.pushTry(12,13),n.state=15;break;case 15:s=void 0,c=r[Symbol.iterator](),n.state=11;break;case 11:n.state=(a=(s=c.next()).done)?9:7;break;case 6:a=!0,n.state=11;break;case 7:l=s.value,n.state=8;break;case 8:return n.state=2,l;case 2:n.maybeThrow(),n.state=4;break;case 4:i-=1,n.state=6;break;case 9:n.popTry(),n.state=13,n.finallyFallThrough=17;break;case 12:n.popTry(),n.maybeUncatchable(),d=n.storedException,n.state=18;break;case 18:o=!0,u=d,n.state=13,n.finallyFallThrough=17;break;case 13:n.popTry(),n.state=24;break;case 24:try{a||null==c.return||c.return()}finally{if(o)throw u}n.state=22;break;case 17:n.state=i>0?25:-2;break;case 25:return n.state=26,t;case 26:n.maybeThrow(),n.state=28;break;case 28:i-=1,n.state=17;break;case 22:n.state=n.finallyFallThrough;break;default:return n.end()}},n,this)}))},sorted:function(){return u(this.toArray().sort())},sortedBy:function(e){return u(this.toArray().sort(function(t,r){var n=e(t),i=e(r);return n<i?-1:n>i?1:0}))},ifThen:function(e,t){return e?new o(t(this)):this},toMap:function(e,t){var r=new Map,n=!0,i=!1,a=void 0;try{for(var o=void 0,u=this._iterable[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=e(s),l=t(s);if(r.has(c))throw new Error("Duplicate key <"+c+">. Came from item <"+s+">.");r.set(c,l)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}return r},keyedBy:function(e){return this.toMap(e,function(e){return e})},groupBy:function(e){var t=new Map,r=!0,n=!1,i=void 0;try{for(var a=void 0,o=this._iterable[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value,s=e(u);t.has(s)||t.set(s,[]),t.get(s).push(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return t},partitioned:function(e){if(e<=0)throw new Error("need partitionSize > 0");var t=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n,i,a,o,u,s,c,l;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=[],i=!0,a=!1,o=void 0,r.state=34;break;case 34:r.pushTry(15,16),r.state=18;break;case 18:u=void 0,s=t[Symbol.iterator](),r.state=14;break;case 14:r.state=(i=(u=s.next()).done)?12:10;break;case 6:i=!0,r.state=14;break;case 10:c=u.value,r.state=11;break;case 11:n.push(c),r.state=9;break;case 9:r.state=n.length>=e?1:6;break;case 1:return r.state=2,n;case 2:r.maybeThrow(),r.state=4;break;case 4:n=[],r.state=6;break;case 12:r.popTry(),r.state=16,r.finallyFallThrough=20;break;case 15:r.popTry(),r.maybeUncatchable(),l=r.storedException,r.state=21;break;case 21:a=!0,o=l,r.state=16,r.finallyFallThrough=20;break;case 16:r.popTry(),r.state=27;break;case 27:try{i||null==s.return||s.return()}finally{if(a)throw o}r.state=25;break;case 20:r.state=n.length>0?28:-2;break;case 28:return r.state=29,n;case 29:r.maybeThrow(),r.state=-2;break;case 25:r.state=r.finallyFallThrough;break;default:return r.end()}},r,this)}))},stride:function(e){return this.filterWithIndex(function(t,r){return r%e==0})},breadthFirstSearch:function(e){var t=void 0!==arguments[1]?arguments[1]:function(e){return e},r=this;return o.fromGenerator($traceurRuntime.initGeneratorFunction(function n(){var i,a,o,u,s,c,l,d,m,f,h;return $traceurRuntime.createGeneratorInstance(function(n){for(;;)switch(n.state){case 0:i=new Set,a=r.toArray(),n.state=16;break;case 16:o=0,n.state=14;break;case 14:n.state=o<a.length?8:-2;break;case 7:o++,n.state=14;break;case 8:u=a[o],s=t(u),n.state=9;break;case 9:n.state=i.has(s)?7:2;break;case 2:i.add(s),c=!0,l=!1,d=void 0;try{for(m=void 0,f=e(u)[Symbol.iterator]();!(c=(m=f.next()).done);c=!0)h=m.value,a.push(h)}catch(e){l=!0,d=e}finally{try{c||null==f.return||f.return()}finally{if(l)throw d}}n.state=11;break;case 11:return n.state=5,u;case 5:n.maybeThrow(),n.state=7;break;default:return n.end()}},n,this)}))}},{fromGenerator:function(e){return new o(e,!0)},range:function(t){if(!Number.isInteger(t)||t<0)throw new e("bad count",{count:t});return o.fromGenerator($traceurRuntime.initGeneratorFunction(function e(){var r;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:r=0,e.state=7;break;case 7:e.state=r<t?1:-2;break;case 4:r++,e.state=7;break;case 1:return e.state=2,r;case 2:e.maybeThrow(),e.state=4;break;default:return e.end()}},e,this)}))},naturals:function(){return o.fromGenerator($traceurRuntime.initGeneratorFunction(function e(){var t;return $traceurRuntime.createGeneratorInstance(function(e){for(;;)switch(e.state){case 0:t=0,e.state=9;break;case 9:e.state=1;break;case 1:return e.state=2,t;case 2:e.maybeThrow(),e.state=4;break;case 4:t++,e.state=9;break;default:return e.end()}},e,this)}))},repeat:function(e,t){if(t<0)throw new Error("needed repeatCount >= 0");return o.fromGenerator($traceurRuntime.initGeneratorFunction(function r(){var n;return $traceurRuntime.createGeneratorInstance(function(r){for(;;)switch(r.state){case 0:n=0,r.state=7;break;case 7:r.state=n<t?1:-2;break;case 4:n++,r.state=7;break;case 1:return r.state=2,e;case 2:r.maybeThrow(),r.state=4;break;default:return r.end()}},r,this)}))}})}(),u=function(e){return new o(e)};return{get THROW_IF_EMPTY(){return t},get seq(){return u},get Seq(){return o}}}),$traceurRuntime.registerModule("src/base/Util.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/base/Util.js")).DetailedError,t=function(){function t(){}return $traceurRuntime.createClass(t,{},{need:function(e,t,r){if(!0!==e){var n=void 0===r?"(not provided)":"["+Array.prototype.slice.call(r).join(", ")+"]",i="Precondition failed\n\nMessage: "+(void 0===t?"(not provided)":t)+"\n\nArgs: "+n;throw new Error(i)}},numberOfSetBits:function(e){if(e<0)throw new Error("i < 0");if(!Number.isInteger(e))throw new Error("!Number.isInteger(i)");if(e>4294967295)throw new Error("i > 0xFFFFFFFF");return e=(1431655765&e)+(e>>1&1431655765),e=(858993459&e)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,255&(e+=e>>16)},bin:function(e,t){return("0".repeat(t)+e.toString(2)).slice(-t).split("").join("")},notNull:function(e){return t.need(null!==e,"notNull"),e},isPowerOf2:function(e){return e>0&&0==(e-1&e)},bitSize:function(e){return t.need(e>=0,"bitSize: n >= 0"),0===e?0:t.floorLg2(e)+1},ceilingPowerOf2:function(e){return e<=1?1:1<<t.ceilLg2(e)},ceilLg2:function(e){if(e<=1)return 0;var t=Math.ceil(Math.log2(e));return 1<<t<e?t+1:e<=1<<t-1?t-1:t},floorLg2:function(e){if(e<=1)return 0;var t=Math.floor(Math.log2(e));return 1<<t+1<=e?t+1:e<1<<t?t-1:t},powerOfTwoness:function(e){if(0===e)return Math.POSITIVE_INFINITY;if(e<0)return t.powerOfTwoness(-e);var r=e&(e^e-1);return Math.round(Math.log2(r))},reverseGroupMap:function(e){var t,r,n=void 0!==arguments[1]&&arguments[1],i=new Map;if(n){var a=!0,o=!1,u=void 0;try{for(var s=void 0,c=e.keys()[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value;i.set(l,[])}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}}var d=!0,m=!1,f=void 0;try{for(var h=void 0,g=e[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=(t=h.value[Symbol.iterator](),(r=t.next()).done?void 0:r.value),v=(r=t.next()).done?void 0:r.value,y=!0,b=!1,R=void 0;try{for(var w=void 0,M=v[Symbol.iterator]();!(y=(w=M.next()).done);y=!0){var _=w.value;i.has(_)||i.set(_,[]),i.get(_).push(p)}}catch(e){b=!0,R=e}finally{try{y||null==M.return||M.return()}finally{if(b)throw R}}}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}return i},binarySearchForTransitionFromTrueToFalse:function(e,t){for(var r=0;e>r;){var n=r+Math.floor((e-r)/2);t(n)?r=n+1:e=n}return r},breakLine:function(e,r,n){if(""===e)return[""];for(var i=[],a=0;a<e.length;){var o=t.binarySearchForTransitionFromTrueToFalse(e.length-a+1,function(t){return n(e.substr(a,t))<=r})-1;o=Math.max(1,o);var u=e.substr(a,o);if(!(a+o===e.length||null!==e.substr(a+o,1).match(/\s/))){var s=/^(.*\S)(\s+)\S*$/.exec(u);if(null!==s){var c=s[1],l=s[2];i.push(c.trim()),a+=c.length+l.length;continue}}i.push(u.trim()),a+=u.length,a+=e.substr(a).match(/^\s*/)[0].length}return i},decomposeObjectValues:function(e){var t,r=[];t=function(e){if(Array.isArray(e)){var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=e[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;t(s)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}}else r.push(e)};var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=Object.keys(e).sort()[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;t(e[s],r)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}return r},recomposedObjectValues:function(e,r){var n,i={},a=0;n=function(e){if(Array.isArray(e)){var t=[],i=!0,o=!1,u=void 0;try{for(var s=void 0,c=e[Symbol.iterator]();!(i=(s=c.next()).done);i=!0){var l=s.value;t.push(n(l))}}catch(e){o=!0,u=e}finally{try{i||null==c.return||c.return()}finally{if(o)throw u}}return t}return r[a++]};var o=!0,u=!1,s=void 0;try{for(var c=void 0,l=Object.keys(e).sort()[Symbol.iterator]();!(o=(c=l.next()).done);o=!0){var d=c.value;i[d]=n(e[d])}}catch(e){u=!0,s=e}finally{try{o||null==l.return||l.return()}finally{if(u)throw s}}return t.need(a===r.length,"Mismatched field value count."),i},objectifyArrayFunc:function(e){return function(r){return t.recomposedObjectValues(r,e(t.decomposeObjectValues(r)))}},snappedCosSin:function(e){var t=Math.PI/4,r=Math.round(e/t);if(r*t===e){var n=Math.sqrt(.5);return[[1,0],[n,n],[0,1],[-n,n],[-1,0],[-n,-n],[0,-1],[n,-n]][7&r]}return[Math.cos(e),Math.sin(e)]},properMod:function(t,r){if(r<=0)throw new e("denominator <= 0",{numerator:t,denominator:r});var n=t%r;return n+(n<0?r:0)},mergeMaps:function(){for(var e,t,r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var i=new Map,a=!0,o=!1,u=void 0;try{for(var s=void 0,c=r[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value,d=!0,m=!1,f=void 0;try{for(var h=void 0,g=l.entries()[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=(e=h.value[Symbol.iterator](),(t=e.next()).done?void 0:t.value),v=(t=e.next()).done?void 0:t.value;i.set(p,v)}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}return i},modular_multiplicative_inverse:function(e,r){var n=t.extended_gcd(e,r),i=n.x;if(1===n.gcd)return(i%=r)<0&&(i+=r),i},extended_gcd:function(e,t){for(var r,n,i,a,o,u,s=0,c=1,l=t,d=1,m=0,f=e;0!==l;){var h=Math.floor(f/l);f=(n=(r=[l,f-h*l][Symbol.iterator]()).next()).done?void 0:n.value,l=(n=r.next()).done?void 0:n.value,d=(a=(i=[s,d-h*s][Symbol.iterator]()).next()).done?void 0:a.value,s=(a=i.next()).done?void 0:a.value,m=(u=(o=[c,m-h*c][Symbol.iterator]()).next()).done?void 0:u.value,c=(u=o.next()).done?void 0:u.value}return{x:d,y:m,gcd:f}},digits_to_superscript_digits:function(e){for(var t=0;t<10;t++)e=e.split("0123456789"[t]).join("⁰¹²³⁴⁵⁶⁷⁸⁹"[t]);return e}})}();return t.STRICT_EQUALITY=function(e,t){return e===t},t.CUSTOM_IS_EQUAL_TO_EQUALITY=function(e,t){return null===e?null===t:void 0===e?void 0===t:e.isEqualTo(t)},{get Util(){return t}}}),$traceurRuntime.registerModule("src/browser/Clipboard.js",[],function(){"use strict";function e(e){if(document.selection){var t=document.body.createTextRange();t.moveToElementText(e),t.select()}else if(window.getSelection){var r=document.createRange();r.selectNodeContents(e),window.getSelection().removeAllRanges(),window.getSelection().addRange(r)}if(!document.execCommand("copy"))throw new Error("execCommand failed")}return{get selectAndCopyToClipboard(){return e}}}),$traceurRuntime.registerModule("src/browser/EventUtil.js",[],function(){"use strict";function e(e){return t.of(t.elementEvent(e,"change"),t.elementEvent(e,"keyup"),t.elementEvent(e,"click"),t.elementEvent(e,"paste"),t.elementEvent(e,"input")).flatten().map(function(t){return e.value}).whenDifferent()}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/browser/EventUtil.js")).Observable;return{get textEditObservable(){return e}}}),$traceurRuntime.registerModule("src/browser/HistoryPusher.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/browser/HistoryPusher.js")).DetailedError,t=function(){return $traceurRuntime.createClass(function(){this._historyActionsNotWorking=!1,this._currentMemorableStateObj=void 0},{currentStateIsMemorableButUnknown:function(){this._currentMemorableStateObj={wont_equal_this:!0}},currentStateIsMemorableAndEqualTo:function(e){this._currentMemorableStateObj=e},currentStateIsNotMemorable:function(){this._currentMemorableStateObj=void 0},stateChange:function(t,r){if(!r.startsWith("#"))throw new e("Expected a hash URL.",{stateObj:t,stateUrlHash:r});if(this._currentMemorableStateObj!==t)if(this._historyActionsNotWorking)document.location.hash=r;else try{void 0===this._currentMemorableStateObj?history.replaceState(t,"",r):(history.pushState(t,"",r),this._currentMemorableStateObj=void 0)}catch(e){console.warn("Calling 'history.replaceState/pushState' failed. Falling back to setting location.hash.",e),this._historyActionsNotWorking=!0,document.location.hash=r}}},{})}();return{get HistoryPusher(){return t}}}),$traceurRuntime.registerModule("src/browser/MouseWatcher.js",[],function(){"use strict";function e(e,t){var n=t.getBoundingClientRect();return new r(e.clientX-n.left,e.clientY-n.top)}function t(e,t,r,n,i){return new o(e,t,r,n,i).addListenersUntilResultInvoked()}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/browser/MouseWatcher.js")).Point,n=function(e){return void 0!==window.TouchEvent&&e instanceof TouchEvent||1===e.which},i=function(e){return 2===e.which},a=function(e,t,r){return e.addEventListener(t,r),function(){return e.removeEventListener(t,r)}},o=function(){return $traceurRuntime.createClass(function(e,t,r,n,i){this._element=e,this._grabHandler=t,this._cancelHandler=r,this._dragHandler=n,this._dropHandler=i,this._grabPointerId=void 0,this._grabActivityTime=window.performance.now(),this._lastPos=void 0,this._lastEv=void 0},{addListenersUntilResultInvoked:function(){var e=this,t=this._element,r=[a(t,"mousedown",function(t){return e.handleMouseEventWith(t,e.onDown)}),a(document,"mousemove",function(t){return e.handleMouseEventWith(t,e.onMove)}),a(document,"mouseup",function(t){return e.handleMouseEventWith(t,e.onUp)}),a(document,"mouseleave",function(t){return e.handleMouseEventWith(t,e.onLeave)}),a(document,"mouseenter",function(t){return e.handleMouseEventWith(t,e.onEnter)}),a(t,"touchstart",function(t){return e.handleTouchEventWith(t,e.onDown)}),a(t,"touchmove",function(t){return e.handleTouchEventWith(t,e.onMove)}),a(t,"touchend",function(t){return e.handleTouchEventWith(t,e.onUp)}),a(t,"touchcancel",function(t){return e.handleTouchEventWith(t,e.onCancel)})];return function(){var e=!0,t=!1,n=void 0;try{for(var i=void 0,a=r[Symbol.iterator]();!(e=(i=a.next()).done);e=!0)(0,i.value)()}catch(e){t=!0,n=e}finally{try{e||null==a.return||a.return()}finally{if(t)throw n}}}},canRegrab:function(){return window.performance.now()>=this._grabActivityTime+5e3},onDown:function(e,t,r){if(n(r)){if(void 0!==this._grabPointerId){if(!this.canRegrab())return;this._dropHandler(this._lastPos,this._lastEv)}this._grabPointerId=t,this._grabActivityTime=window.performance.now(),this._lastPos=e,this._lastEv=r,this._grabHandler(e,r)}},onMove:function(e,t,r){if(this._grabPointerId===t){if(!n(r))return this._lastPos=void 0,this._lastEv=void 0,this._grabPointerId=void 0,void this._dropHandler(void 0,r);this._grabActivityTime=window.performance.now(),this._lastPos=e,this._lastEv=r,this._dragHandler(e,r)}},onCancel:function(e,t,r){this._grabPointerId===t&&(this._lastPos=void 0,this._lastEv=void 0,this._grabPointerId=void 0,this._cancelHandler(r))},onUp:function(e,t,r){n(r)&&this._grabPointerId===t&&(this._lastPos=void 0,this._lastEv=void 0,this._grabPointerId=void 0,this._dropHandler(e,r))},onLeave:function(e,t,r){n(r)&&this._grabPointerId===t&&(this._grabActivityTime=window.performance.now(),this._lastPos=void 0,this._lastEv=r,this._dragHandler(void 0,r))},onEnter:function(e,t,r){n(r)||this._grabPointerId!==t||(this._lastPos=void 0,this._lastEv=void 0,this._grabPointerId=void 0,this._dropHandler(void 0,r))},relativeEventPos:function(t){return e(t,this._element)},handleTouchEventWith:function(e,t){for(var r=0;r<e.changedTouches.length;r++){var n=e.changedTouches[r];t.call(this,this.relativeEventPos(n),n.identifier,e)}},handleMouseEventWith:function(e,t){t.call(this,this.relativeEventPos(e),"mouse!",e)}},{})}();return{get watchDrags(){return t},get isLeftClicking(){return n},get isMiddleClicking(){return i},get eventPosRelativeTo(){return e}}}),$traceurRuntime.registerModule("src/browser/Polyfills.js",[],function(){"use strict";Float32Array.prototype.slice=Float32Array.prototype.slice||function(e,t){return new Float32Array(Array.from(this).slice(e,t))},Float64Array.prototype.slice=Float64Array.prototype.slice||function(e,t){return new Float64Array(Array.from(this).slice(e,t))},Uint32Array.prototype.slice=Uint32Array.prototype.slice||function(e,t){return new Uint32Array(Array.from(this).slice(e,t))},Int32Array.prototype.slice=Int32Array.prototype.slice||function(e,t){return new Int32Array(Array.from(this).slice(e,t))},Uint16Array.prototype.slice=Uint16Array.prototype.slice||function(e,t){return new Uint16Array(Array.from(this).slice(e,t))},Int16Array.prototype.slice=Int16Array.prototype.slice||function(e,t){return new Int16Array(Array.from(this).slice(e,t))},Uint8Array.prototype.slice=Uint8Array.prototype.slice||function(e,t){return new Uint8Array(Array.from(this).slice(e,t))},Int8Array.prototype.slice=Int8Array.prototype.slice||function(e,t){return new Int8Array(Array.from(this).slice(e,t))};var e=function(){var e=this;return $traceurRuntime.initGeneratorFunction(function t(){var r;return $traceurRuntime.createGeneratorInstance(function(t){for(;;)switch(t.state){case 0:r=0,t.state=7;break;case 7:t.state=r<e.length?1:-2;break;case 4:r++,t.state=7;break;case 1:return t.state=2,e[r];case 2:t.maybeThrow(),t.state=4;break;default:return t.end()}},t,this)})()};Float32Array.prototype[Symbol.iterator]=Float32Array.prototype[Symbol.iterator]||e,Float64Array.prototype[Symbol.iterator]=Float64Array.prototype[Symbol.iterator]||e,Uint32Array.prototype[Symbol.iterator]=Uint32Array.prototype[Symbol.iterator]||e,Uint16Array.prototype[Symbol.iterator]=Uint16Array.prototype[Symbol.iterator]||e,Uint8Array.prototype[Symbol.iterator]=Uint8Array.prototype[Symbol.iterator]||e,Int32Array.prototype[Symbol.iterator]=Int32Array.prototype[Symbol.iterator]||e,Int16Array.prototype[Symbol.iterator]=Int16Array.prototype[Symbol.iterator]||e,Int8Array.prototype[Symbol.iterator]=Int8Array.prototype[Symbol.iterator]||e,window.performance=window.performance||{},window.performance.now=window.performance.now||function(){return Date.now()};var t=WebGLRenderingContext;if(void 0!==t&&void 0===t.INVALID_ENUM){var r=["ARRAY_BUFFER","CLAMP_TO_EDGE","COLOR_ATTACHMENT0","COMPILE_STATUS","ELEMENT_ARRAY_BUFFER","FLOAT","FRAGMENT_SHADER","FRAMEBUFFER","FRAMEBUFFER_COMPLETE","HIGH_FLOAT","LINK_STATUS","MAX_TEXTURE_IMAGE_UNITS","MAX_TEXTURE_SIZE","MEDIUM_FLOAT","NEAREST","NO_ERROR","RGBA","STATIC_DRAW","TEXTURE_2D","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","TEXTURE0","TRIANGLES","UNSIGNED_SHORT","UNSIGNED_BYTE","VALIDATE_STATUS","VERTEX_SHADER"],n=document.createElement("canvas").getContext("webgl");if(null!==n&&void 0!==n){var i=!0,a=!1,o=void 0;try{for(var u=void 0,s=r[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value;t[c]=t[c]||n[c]}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}}}return{}}),$traceurRuntime.registerModule("src/browser/SaveFile.js",[],function(){"use strict";function e(e,t){if(navigator.msSaveBlob)navigator.msSaveBlob(new Blob([t],{type:"text/html;charset=UTF-8"}),e);else{var r=document.createElement("a");r.href=void 0!==window.URL?window.URL.createObjectURL(new Blob([t],{type:"text/html;charset=UTF-8"})):"data:application/octet-stream,"+encodeURI(moddedHtml),r.download=e;try{document.body.appendChild(r),r.click()}finally{document.body.removeChild(r)}}}return{get saveFile(){return e}}}),$traceurRuntime.registerModule("src/browser/TouchScrollBlocker.js",[],function(){"use strict";$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/browser/TouchScrollBlocker.js")).Rect;var e=function(){return $traceurRuntime.createClass(function(e){this._parentElement=e,this._curBlockers=[],this._curShowing=0},{setBlockers:function(e,t){for(;this._curBlockers.length<e.length;){var r=document.createElement("div");r.style.touchAction="none",r.style.position="absolute",r.style.opacity=1e-4,this._parentElement.appendChild(r),this._curBlockers.push({div:r,area:void 0})}for(var n=0;n<e.length;n++){var i=e[n].rect,a=t||e[n].cursor||"auto",o=this._curBlockers[n],u=o.div.style;i.isEqualTo(o.area)||(o.area=i,u.left=i.x+"px",u.top=i.y+"px",u.width=i.w+"px",u.height=i.h+"px"),u.cursor!==a&&(u.cursor=a)}for(;this._curShowing<e.length;)this._curBlockers[this._curShowing].div.style.display="inline",this._curShowing++;for(;this._curShowing>e.length;)this._curShowing--,this._curBlockers[this._curShowing].div.style.display="none"}},{})}();return{get TouchScrollBlocker(){return e}}}),$traceurRuntime.registerModule("src/circuit/CircuitComputeUtil.js",[],function(){"use strict";function e(e,r){return e.setActualEffectToUpdateFunc(function(e){return t(e,r.withDisabledReasonsForEmbeddedContext(e.row,e.customContextFromGates),!1)}).setKnownEffectToCircuit(r).setExtraDisableReasonFinder(function(e){for(var t=r.withDisabledReasonsForEmbeddedContext(e.outerRow,e.context),n=0;n<t.numWires;n++)for(var i=0;i<t.columns.length;i++){var a=t.gateAtLocIsDisabledReason(i,n);if(void 0!==a)return a;if(t.gateInSlot(i,n)===s.Special.Measurement)return"hidden\nmeasure\nbroken"}})}function t(e,t,i){for(var a=[],s=[],c=[],l=[],d=0;d<t.columns.length;d++)n(e,t,d,function(e){return function(n){if(i){var o=r(n,t,e),u=o.qubitDensities,d=o.norm,m=o.customGateStats;a.push(u),c.push(d);var f=!0,h=!1,g=void 0;try{for(var p=void 0,v=m[Symbol.iterator]();!(f=(p=v.next()).done);f=!0){var y=p.value,b=y.row,R=y.stat;l.push({col:e,row:b,out:s.length}),s.push(R)}}catch(e){h=!0,g=e}finally{try{f||null==v.return||v.return()}finally{if(h)throw g}}}}}(d));if(i){var m=(1<<t.numWires)-1;a.push(o.superpositionToQubitDensities(e.stateTrader.currentTexture,u.NONE,m))}return{colQubitDensities:a,colNorms:c,customStats:s,customStatsMap:l}}function r(e,t,r){var n=[],a=!0,u=!1,s=void 0;try{for(var l=void 0,d=t.customStatRowsInCol(r)[Symbol.iterator]();!(a=(l=d.next()).done);a=!0){var m=l.value,f=new i(e.time,m,t.numWires,e.controls,e.controlsTexture,e.stateTrader,c.mergeMaps(e.customContextFromGates,t.colCustomContextFromGates(r,m))),h=t.columns[r].gates[m].customStatTexturesMaker(f);n.push({row:m,stat:h})}}catch(e){u=!0,s=e}finally{try{a||null==d.return||d.return()}finally{if(u)throw s}}var g=o.superpositionToQubitDensities(e.stateTrader.currentTexture,e.controls,t.colDesiredSingleQubitStatsMask(r)),p=void 0!==t.columns[r].indexOfNonUnitaryGate();return{qubitDensities:g,norm:o.superpositionToNorm(e.stateTrader.currentTexture,p),customGateStats:n}}function n(e,t,r,n){var o=e.controls.and(t.colControls(r).shift(e.row)),u=a.controlMask(o).toBoolTexture(e.wireCount),s=c.mergeMaps(e.customContextFromGates,t.colCustomContextFromGates(r,e.row)),l=e.stateTrader,d=new i(e.time,e.row,e.wireCount,e.controls,e.controlsTexture,l,s),m=new i(e.time,e.row,e.wireCount,o,u,l,s);t.applyBeforeOperationsInCol(r,d),t.applyMainOperationsInCol(r,m),n(m),t.applyAfterOperationsInCol(r,d),u.deallocByDepositingInPool("controlTex in _advanceStateWithCircuitDefinitionColumn")}var i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitEvalContext.js","src/circuit/CircuitComputeUtil.js")).CircuitEvalContext,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/circuit/CircuitComputeUtil.js")).CircuitShaders,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetTextureUtil.js","src/circuit/CircuitComputeUtil.js")).KetTextureUtil,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/circuit/CircuitComputeUtil.js")).Controls,s=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/circuit/CircuitComputeUtil.js")).GateBuilder,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/circuit/CircuitComputeUtil.js")).Gates),c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/CircuitComputeUtil.js")).Util;return{get setGateBuilderEffectToCircuit(){return e},get advanceStateWithCircuit(){return t}}}),$traceurRuntime.registerModule("src/circuit/CircuitDefinition.js",[],function(){"use strict";function e(e,r,n,i){var a,o,u,s,c=(a=t(e,r)[Symbol.iterator](),(o=a.next()).done?void 0:o.value),l=(o=a.next()).done?void 0:o.value,d=(u=t(e,n)[Symbol.iterator](),(s=u.next()).done?void 0:s.value),m=(s=u.next()).done?void 0:s.value;if(void 0!==d&&void 0!==c)return{first:Math.min(c,d),last:Math.max(l,m),measured:i}}function t(e,t){for(var r=void 0,n=void 0,i=0;i<e;i++)t(i)&&(void 0===r&&(r=i),n=i);return[r,n]}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/circuit/CircuitDefinition.js")).CircuitShaders,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/circuit/CircuitDefinition.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/circuit/CircuitDefinition.js")).Controls,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CustomGateSet.js","src/circuit/CircuitDefinition.js")).CustomGateSet,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/CircuitDefinition.js")).DetailedError,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/circuit/CircuitDefinition.js")).Gate,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateColumn.js","src/circuit/CircuitDefinition.js")).GateColumn,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateShaders.js","src/circuit/CircuitDefinition.js")).GateShaders,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/circuit/CircuitDefinition.js")).Gates,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/circuit/CircuitDefinition.js")).Point,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/circuit/CircuitDefinition.js")),f=m.seq,h=m.Seq,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/CircuitDefinition.js")).Util,p=function(){function t(e,t){var r=void 0!==arguments[2]?arguments[2]:0,n=void 0!==arguments[3]?arguments[3]:new Map,i=void 0!==arguments[4]?arguments[4]:new a,u=void 0!==arguments[5]&&arguments[5];if(e<0)throw new o("Bad numWires",{numWires:e});if(!Array.isArray(t))throw new o("Bad columns",{numWires:e,columns:t});if(!t.every(function(e){return e instanceof s}))throw new o("Not a GateColumn",{columns:t});if(!t.every(function(t){return t.gates.length===e}))throw new o("Wrong gate count in a column",{numWires:e,columns:t});this.numWires=e,this.columns=t,this.customGateSet=i,this.outerRowOffset=r,this.outerContext=n,this.isNested=u,this._colRowDisabledReason=[],this._measureMasks=[0];var c=0,l=new Map,d=!0,m=!1,f=void 0;try{for(var h=void 0,g=t[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=h.value,v=p.perRowDisabledReasons(c,r,n,l,u),y=v.allReasons,b=v.stickyCtx;c=p.nextMeasureMask(c,y),this._colRowDisabledReason.push(y),this._measureMasks.push(c),l=b}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}this._gateSlotCoverMap=this._computeGateSlotCoverMap(),this._cachedColumnContexts=new Map}return $traceurRuntime.createClass(t,{gateWeight:function(){return f(this.columns).flatMap(function(e){return e.gates}).filter(function(e){return void 0!==e}).map(function(e){return void 0===e.knownCircuit?1:e.knownCircuit.gateWeight()}).sum()},hasControls:function(){return!this.columns.every(function(e){return!e.hasControl(-1)})},hasOnlyUnitaryGates:function(){return this.columns.every(function(e){return void 0===e.indexOfNonUnitaryGate()})},hasNonControlGates:function(){var e=function(e){return!e.gates.every(function(e){return void 0===e||e.isControl()})};return!this.columns.every(function(t){return!e(t)})},countGatesUpTo:function(e){var t=0,r=!0,n=!1,i=void 0;try{for(var a=void 0,o=this.columns[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value,s=!0,c=!1,l=void 0;try{for(var d=void 0,m=u.gates[Symbol.iterator]();!(s=(d=m.next()).done);s=!0)if(void 0!==d.value&&++t>=e)return t}catch(e){c=!0,l=e}finally{try{s||null==m.return||m.return()}finally{if(c)throw l}}}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return t},getUnmetContextKeys:function(){for(var e=new Set,t=0;t<this.columns.length;t++){var r=this.columns[t],n=this.colCustomContextFromGates(t,0),i=!0,a=!1,o=void 0;try{for(var u=void 0,s=r.gates[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value,l=!0,d=!1,m=void 0;try{for(var f=void 0,h=(void 0===c?[]:c.getUnmetContextKeys())[Symbol.iterator]();!(l=(f=h.next()).done);l=!0){var g=f.value,p=g.replace("Input Range ","Input Default ").replace("Input NO_DEFAULT Range ","Input Range ");n.has(g)||n.has(p)||e.add(g)}}catch(e){d=!0,m=e}finally{try{l||null==h.return||h.return()}finally{if(d)throw m}}}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}}return e},withDisabledReasonsForEmbeddedContext:function(e,r){return new t(this.numWires,this.columns,e,r,this.customGateSet,!0)},_computeGateSlotCoverMap:function(){for(var e=new Map,t=0;t<this.columns.length;t++)for(var r=0;r<this.numWires;r++){var n=this.columns[t].gates[r];if(void 0!==n)for(var i=0;i<n.width;i++)for(var a=0;a<n.height;a++)e.set(t+i+":"+(r+a),{col:t,row:r,gate:n})}return e},isEmpty:function(){return 0===this.columns.length},isEqualTo:function(e){return this===e||e instanceof t&&this.numWires===e.numWires&&f(this.columns).isEqualTo(f(e.columns),g.CUSTOM_IS_EQUAL_TO_EQUALITY)},toString:function(){var e=this,t=function(e){return"─".repeat(e)},r=function(e,r){return t(Math.floor(e-r.length)/2)+r+t(Math.ceil(e-r.length)/2)},n=h.range(this.columns.length).map(function(t){return f(e.columns[t].gates).map(function(e){return void 0===e?0:e.serializedId.length}).max()}).toArray();return"CircuitDefinition ("+this.numWires+" wires, "+this.columns.length+" cols):\n\t"+h.range(this.numWires).map(function(i){return t(1)+h.range(e.columns.length).map(function(t){var a=e.columns[t].gates[i],o=void 0===a?"":a.serializedId;return r(n[t],o)}).join(t(1))+t(1)}).join("\n\t")},stableDuration:function(){return f(this.columns).flatMap(function(e){return e.gates}).filter(function(e){return void 0!==e}).map(function(e){return e.stableDuration()}).min(1/0)},readableHash:function(){var e=f(this.columns).flatMap(function(e){return e.gates}).filter(function(e){return void 0!==e}).map(function(e){return e.symbol}).toArray();if(0===e.length)return n.EMPTY_CIRCUIT_TITLE;var t=this.numWires+" wires, "+e.length+" ops, "+e.join("").split("^").join("");return t.length<=40?t:t.substring(0,40)+"…"},withColumns:function(e){return new t(this.numWires,e,this.outerRowOffset,this.outerContext,this.customGateSet)},_usedColumns:function(){for(var e=new Set,t=0;t<this.columns.length;t++)for(var r=0;r<this.columns[t].maximumGateWidth();r++)e.add(t+r);return e},_findWidthWiseOverlapInRect:function(e,t,r,n){for(var i=1;i<r&&e+i<this.columns.length;i++)for(var a=0;a<n;a++){var o=this.findGateCoveringSlot(e+i,t+a);if(void 0!==o&&o.col!==e)return{col:o.col,row:o.row}}},withWidthOverlapsFixed:function(){for(var e=this,t=[],r=this,n=0;n<this.columns.length;n++)!function(n){var i=h.range(r.numWires).map(function(t){var r=e.columns[n].gates[t];if(void 0===r)return 0;var i=e._findWidthWiseOverlapInRect(n,t,r.width,r.height);return void 0===i?0:r.width-(i.col-n)}).max(0);t.push(r.columns[n]);for(var a=0;a<i;a++)t.push(s.empty(r.numWires))}(n);return this.withColumns(t)},_findHeightWiseOverlapsInCol:function(e){for(var t=new Set,r=0,n=0;n<this.numWires;n++){r-=1;var i=this.gateInSlot(e,n);void 0!==i&&(r>0&&t.add(n),r=Math.max(r,i.height))}return t},withHeightOverlapsFixed:function(){var e=void 0!==arguments[0]?arguments[0]:5,t=[],r=this;e:for(var n=0;n<this.columns.length;n++)switch(function(e){var n=r._findHeightWiseOverlapsInCol(e);if(0===n.size)return t.push(r.columns[e]),0;var i=f(r.columns[e].gates).mapWithIndex(function(e,t){return n.has(t)?void 0:e}).toArray(),a=f(r.columns[e].gates).mapWithIndex(function(e,t){return void 0!==e&&(e.isControl()||n.has(t))?e:void 0}).toArray();t.push(new s(i)),t.push(new s(a))}(n)){case 0:continue e}var i=this.withColumns(t);return t.length>this.columns.length&&e>0&&(i=i.withHeightOverlapsFixed(e-1)),i},withTrailingSpacersIncluded:function(){var e=void 0!==arguments[0]?arguments[0]:0;return this.withColumns($traceurRuntime.spread(this.columns,new Array(Math.max(0,this.minimumRequiredColCount()+e-this.columns.length)).fill(s.empty(this.numWires))))},trimEmptyColumnsAtEndIgnoringGateWidths:function(){for(var e=this.columns.length;;e--)if(0===e||!this.columns[e-1].isEmpty())return this.withColumns(this.columns.slice(0,e))},withUncoveredColumnsRemoved:function(){var e=this._usedColumns();return new t(this.numWires,f(this.columns).filterWithIndex(function(t,r){return e.has(r)}).toArray(),this.outerRowOffset,this.outerContext,this.customGateSet)},withWireCount:function(e){return e===this.numWires?this:new t(e,this.columns.map(function(t){return new s($traceurRuntime.spread(t.gates.slice(0,e),new Array(Math.max(0,e-t.gates.length)).fill(void 0)))}),this.outerRowOffset,this.outerContext,this.customGateSet)},minimumRequiredWireCount:function(){var e=1,t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this.columns[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e=Math.max(e,o.minimumRequiredWireCount())}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}return e},withMinimumWireCount:function(){return this.withWireCount(this.minimumRequiredWireCount())},minimumRequiredColCount:function(){for(var e=0,t=0;t<this.columns.length;t++)e=Math.max(e,this.columns[t].maximumGateWidth()+t);return e},colIsMeasuredMask:function(e){return e<0?0:this._measureMasks[Math.min(e,this.columns.length)]},colDesiredSingleQubitStatsMask:function(e){if(e<0||e>=this.columns.length)return 0;for(var t=this.columns[e],r=0,n=0;n<t.gates.length;n++)void 0!==t.gates[n]&&t.gates[n].isSingleQubitDisplay&&void 0===this.gateAtLocIsDisabledReason(e,n)&&(r|=1<<n);return r},colCustomContextFromGates:function(e,t){if(e<0||e>=this.columns.length)return new Map;var r=""+t,n=this._cachedColumnContexts.get(r);return void 0===n&&(n=this._uncached_customContextFromGates(t),this._cachedColumnContexts.set(r,n)),n[e]},_uncached_customContextFromGates:function(e){for(var t=[],r=new Map,n=0;n<this.columns.length;n++){for(var i=new Map(r),a=this.columns[n],o=0;o<a.gates.length;o++){var u=a.gates[o];if(void 0!==u&&void 0===this.gateAtLocIsDisabledReason(n,o)){var s=!0,c=!1,l=void 0;try{for(var d=void 0,m=u.customColumnContextProvider(e+o,u)[Symbol.iterator]();!(s=(d=m.next()).done);s=!0){var f=d.value,h=f.key,g=f.val;i.set(h,g),u.isContextTemporary||r.set(h,g)}}catch(e){c=!0,l=e}finally{try{s||null==m.return||m.return()}finally{if(c)throw l}}}}t.push(i)}return t},locIsMeasured:function(e){var t=e.y;return!(t<0||t>=this.numWires)&&0!=(this.colIsMeasuredMask(e.x)&1<<t)},locClassifyMeasuredIncludingGateExtension:function(e){var t=e.y;if(t<0||t>=this.numWires)return!1;var r=this.columns[e.x].gates[t],n=void 0===r?1:r.height,i=this.colIsMeasuredMask(e.x)>>t&(1<<n)-1;return 0!==i&&(i===(1<<n)-1||void 0)},gateInSlot:function(e,t){if(!(e<0||e>=this.columns.length||t<0||t>=this.numWires)){var r=this.columns[e].gates[t];return void 0===r?void 0:r}},findGateCoveringSlot:function(e,t){var r=e+":"+t;if(this._gateSlotCoverMap.has(r))return this._gateSlotCoverMap.get(r)},locIsControlWireStarter:function(e){var t=this.gateInSlot(e.x,e.y);return void 0!==t&&t.isControlWireSource},locStartsSingleControlWire:function(e){return this.locIsControlWireStarter(e)&&!0!==this.locClassifyMeasuredIncludingGateExtension(e)&&void 0===this.gateAtLocIsDisabledReason(e.x,e.y)},locStartsDoubleControlWire:function(e){return this.locIsControlWireStarter(e)&&!1!==this.locClassifyMeasuredIncludingGateExtension(e)&&void 0===this.gateAtLocIsDisabledReason(e.x,e.y)},colGetEnabledSwapGate:function(e){if(!(e<0||e>=this.columns.length)){for(var t=[],r=0;r<this.numWires;r++)if(this.gateInSlot(e,r)===l.Special.SwapHalf){if(void 0!==this.gateAtLocIsDisabledReason(e,r))return;t.push(r)}if(2===t.length)return t}},locProvidesStat:function(e,t){var r=this.gateInSlot(e.x,e.y);return void 0!==r&&!r.customColumnContextProvider(0,r).every(function(e){return e.key!==t})},locNeedsStat:function(e,t){var r=this.gateInSlot(e.x,e.y);return void 0!==r&&r.getUnmetContextKeys().has(t)},locHasControllableGate:function(e){var t=this.gateInSlot(e.x,e.y);return void 0!==t&&t.interestedInControls},colHasControls:function(e){return!(e<0||e>=this.columns.length)&&this.columns[e].hasControl()},colHasSingleWireControl:function(e){return!(e<0||e>=this.columns.length)&&this.columns[e].hasCoherentControl(this._measureMasks[e])},colHasDoubleWireControl:function(e){return!(e<0||e>=this.columns.length)&&this.columns[e].hasMeasuredControl(this._measureMasks[e])},colControls:function(e){if(e<0||e>=this.columns.length)return i.NONE;for(var t=i.NONE,r=this.columns[e],n=0;n<r.gates.length;n++){var a=r.gates[n];if(void 0!==a&&void 0===this.gateAtLocIsDisabledReason(e,n)){var o=a.controlBit();void 0!==o&&(t=t.and(i.bit(n,o)))}}return t},gateAtLocIsDisabledReason:function(e,t){if(!(e<0||t<0||e>=this._colRowDisabledReason.length||t>=this.numWires))return this._colRowDisabledReason[e][t]},applyMainOperationsInCol:function(e,t){var n,i;if(!(e<0||e>=this.columns.length)){this._applyOpsInCol(e,t,function(e){if(!e.definitelyHasNoEffect()&&e!==l.Special.SwapHalf)return void 0!==e.customOperation?e.customOperation:function(t){return c.applyMatrixOperation(t,e.knownMatrixAt(t.time))}});var a=this.colGetEnabledSwapGate(e);if(void 0!==a){var o=(n=a[Symbol.iterator](),(i=n.next()).done?void 0:i.value),u=(i=n.next()).done?void 0:i.value;t.applyOperation(r.swap(t.withRow(o+t.row),u+t.row))}}},applyBeforeOperationsInCol:function(e,t){this._applyOpsInCol(e,t,function(e){return e.customBeforeOperation})},applyAfterOperationsInCol:function(e,t){this._applyOpsInCol(e,t,function(e){return e.customAfterOperation})},_applyOpsInCol:function(e,t,r){if(!(e<0||e>=this.columns.length))for(var n=this.columns[e],i=0;i<this.numWires;i++){var a=n.gates[i];if(void 0!==a&&void 0===this.gateAtLocIsDisabledReason(e,i)){var o=r(a);void 0!==o&&o(t.withRow(t.row+i))}}},customStatRowsInCol:function(e){if(e<0||e>=this.columns.length)return[];for(var t=this.columns[e],r=[],n=0;n<t.gates.length;n++)void 0!==t.gates[n]&&void 0!==t.gates[n].customStatTexturesMaker&&void 0===this.gateAtLocIsDisabledReason(e,n)&&r.push(n);return r},isSlotRectCoveredByGateInSameColumn:function(e,t,r){for(var n=0;n<r;n++){var i=this.findGateCoveringSlot(e,t+n);if(void 0!==i&&i.col===e)return!0}return!1},withCustomGate:function(e){return new t(this.numWires,this.columns,this.outerRowOffset,this.outerContext,this.customGateSet.withGate(e))},controlLinesRanges:function(t){var r=this,n=this.columns[t].gates.length,i=this.colGetEnabledSwapGate(t),a=function(e){return new d(t,e)},o=function(e){return r.locHasControllableGate(a(e))},u=function(e){return void 0!==i&&-1!==i.indexOf(e)},s=function(e){return!0!==r.locClassifyMeasuredIncludingGateExtension(a(e))},c=function(e){return!1!==r.locClassifyMeasuredIncludingGateExtension(a(e))},m=[e(n,u,u,!1),e(n,o,function(e){return r.locStartsSingleControlWire(a(e))},!1),e(n,o,function(e){return r.locStartsDoubleControlWire(a(e))},!0)],f=!0,h=!1,g=void 0;try{for(var p=void 0,v=l.InputGates.Letters[Symbol.iterator]();!(f=(p=v.next()).done);f=!0)!function(){var t=p.value,i="Input Range "+t,o="Input Default "+t,u="Input NO_DEFAULT Range "+t,l=function(e){return r.locProvidesStat(a(e),i)||r.locProvidesStat(a(e),o)},d=function(e){return r.locNeedsStat(a(e),i)||r.locNeedsStat(a(e),u)};m.push(e(n,function(e){return l(e)&&s(e)},d,!1),e(n,function(e){return l(e)&&c(e)},d,!0))}()}catch(e){h=!0,g=e}finally{try{f||null==v.return||v.return()}finally{if(h)throw g}}return m.filter(function(e){return void 0!==e})}},{fromTextDiagram:function(e,r){var n=f(r.split("\n")).map(function(e){return e.trim()}).filter(function(e){return""!==e}).toArray();if(f(n.map(function(e){return e.length})).distinct().count()>1)throw new o("Uneven diagram",{diagram:r});var i=n.length,a=n.length>0?n[0].length:0,c=function(t,r){for(var i=1;r+i<n.length;i++)if(null!==e.get(n[r+i][t]))return i;return n.length-r};return new t(i,h.range(a).map(function(t){return new s(f(n).mapWithIndex(function(r,n){var i=r[t];if(!e.has(i))throw new o("Unspecified gate",{char:i});var a=e.get(i);if(null!==a&&void 0!==a){if(a.hasOwnProperty("ofSize"))return a.ofSize(c(t,n));if(a instanceof u)return a;throw new o("Not a gate",a)}}).toArray())}).toArray())}})}();return p.EMPTY=new p(0,[]),{get CircuitDefinition(){return p}}}),$traceurRuntime.registerModule("src/circuit/CircuitEvalContext.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/circuit/CircuitEvalContext.js")).WglConfiguredShader,t=function(){function t(e,t,r,n,i,a,o){this.time=e,this.row=t,this.wireCount=r,this.controls=n,this.controlsTexture=i,this.stateTrader=a,this.customContextFromGates=o}return $traceurRuntime.createClass(t,{applyOperation:function(t){var r=t instanceof e?t:t(this);this.stateTrader.shadeAndTrade(r)},_clone:function(){return new t(this.time,this.row,this.wireCount,this.controls,this.controlsTexture,this.stateTrader,this.customContextFromGates)},withRow:function(e){var t=this._clone();return t.row=e,t},withInputSetToRange:function(e,t,r){var n=this._clone();return n.customContextFromGates=new Map(n.customContextFromGates),n.customContextFromGates.set("Input Range "+e,{offset:t,length:r}),n},withInputSetToConstant:function(e,t){var r=this._clone();return r.customContextFromGates=new Map(r.customContextFromGates),r.customContextFromGates.delete("Input Range "+e),r.customContextFromGates.set("Input Default "+e,t),r},withInputSetToOtherInput:function(e,t){var r=this._clone();r.customContextFromGates=new Map(r.customContextFromGates);var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=["Range","Default"][Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=r.customContextFromGates.get("Input "+s+" "+t);void 0!==c?r.customContextFromGates.set("Input "+s+" "+e,c):r.customContextFromGates.delete("Input "+s+" "+e)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}return r}},{})}();return{get CircuitEvalContext(){return t}}}),$traceurRuntime.registerModule("src/circuit/CircuitShaders.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/circuit/CircuitShaders.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/circuit/CircuitShaders.js")).Controls,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/circuit/CircuitShaders.js")),n=r.ketArgs,i=r.ketShaderPermute,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/circuit/CircuitShaders.js")).Shaders,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/CircuitShaders.js")).Util,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/circuit/CircuitShaders.js")).WglArg,s=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/circuit/CircuitShaders.js")).WglConfiguredShader,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/circuit/CircuitShaders.js"))),c=s.currentShaderCoder,l=s.makePseudoShaderWithInputsAndOutputAndCode,d=s.Inputs,m=s.Outputs,f=function(){return $traceurRuntime.createClass(function(){},{},{})}();f.classicalState=function(e){return h(u.float("state",e))};var h=l([],m.vec2(),"\n uniform float state;\n vec2 outputFor(float k) {\n return vec2(float(k == state), 0.0);\n }");f.linearOverlay=function(e,t,r){return g(r,t,u.float("offset",e))};var g=l([d.vec4("back"),d.vec4("fore")],m.vec4(),"\n uniform float offset;\n vec4 outputFor(float k) {\n // Note: can't use multiplication to combine because it spreads NaNs from the background into the foreground.\n return k >= offset && k < offset + len_fore() ? read_fore(k - offset) : read_back(k);\n }");f.controlMask=function(e){return e.isEqualTo(t.NONE)?a.color(1,0,0,0):p(u.float("used",e.inclusionMask),u.float("desired",e.desiredValueMask))};var p=l([],m.bool(),"\n uniform float used;\n uniform float desired;\n\n bool outputFor(float k) {\n float pass = 1.0;\n float bit = 1.0;\n for (int i = 0; i < "+e.MAX_SIMULATION_WIRE_COUNT+"; i++) {\n float v = mod(floor(k/bit), 2.0);\n float u = mod(floor(used/bit), 2.0);\n float d = mod(floor(desired/bit), 2.0);\n pass *= 1.0 - abs(v-d)*u;\n bit *= 2.0;\n }\n return pass == 1.0;\n }");f.controlSelect=function(e,r){return e.isEqualTo(t.NONE)?a.passthrough(r):v(r,u.float("used",e.inclusionMask),u.float("desired",e.desiredValueMask))};var v=l([d.vec2("input")],m.vec2(),"\n uniform float used;\n uniform float desired;\n\n /**\n * Inserts bits from the given value into the holes between used bits in the desired mask.\n */\n float scatter(float k) {\n float maskPos = 1.0;\n float coordPos = 1.0;\n float result = 0.0;\n for (int i = 0; i < "+e.MAX_SIMULATION_WIRE_COUNT+"; i++) {\n float v = mod(floor(k/coordPos), 2.0);\n float u = mod(floor(used/maskPos), 2.0);\n float d = mod(floor(desired/maskPos), 2.0);\n result += (v + u*(d-v)) * maskPos;\n coordPos *= 2.0-u;\n maskPos *= 2.0;\n }\n return result;\n }\n\n vec2 outputFor(float k) {\n return read_input(scatter(k));\n }");f.swap=function(e,t){var r;return(r=y).withArgs.apply(r,$traceurRuntime.spread(n(e,t-e.row+1)))};var y=i("","\n float low_bit = mod(out_id, 2.0);\n float mid_bits = floor(mod(out_id, span*0.5)*0.5);\n float high_bit = floor(out_id*2.0/span);\n return high_bit + mid_bits*2.0 + low_bit*span*0.5;");f.qubitDensities=function(e){var t=arguments[1];void 0===t&&(t=(1<<c().vec2.arrayPowerSizeOfTexture(e))-1);var r=o.ceilingPowerOf2(o.numberOfSetBits(t));return b(e,u.float("keptCount",r),u.float("keptBitMask",t))};var b=l([d.vec2("input")],m.vec4(),"\n uniform float keptCount;\n uniform float keptBitMask;\n\n float scatter(float val, float used) {\n float result = 0.0;\n float posUsed = 1.0;\n float posVal = 1.0;\n for (int i = 0; i < "+e.MAX_SIMULATION_WIRE_COUNT+"; i++) {\n float u = mod(floor(used/posUsed), 2.0);\n float v = mod(floor(val/posVal), 2.0);\n result += u * v * posUsed;\n posVal *= 1.0+u;\n posUsed *= 2.0;\n }\n return result;\n }\n\n vec4 outputFor(float k) {\n float bitIndex = mod(k, keptCount);\n float otherBits = floor(k / keptCount);\n float bit = scatter(exp2(bitIndex), keptBitMask);\n\n // Indices of the two complex values making up the current conditional ket.\n float srcIndex0 = mod(otherBits, bit) + floor(otherBits / bit) * bit * 2.0;\n float srcIndex1 = srcIndex0 + bit;\n\n // Grab the two complex values.\n vec2 w1 = read_input(srcIndex0);\n vec2 w2 = read_input(srcIndex1);\n\n // Compute density matrix components.\n float a = dot(w1, w1);\n float br = dot(w1, w2);\n float bi = dot(vec2(-w1.y, w1.x), w2);\n float d = dot(w2, w2);\n\n return vec4(a, br, bi, d);\n }");return{get CircuitShaders(){return f}}}),$traceurRuntime.registerModule("src/circuit/CircuitStats.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/circuit/CircuitStats.js")).CircuitDefinition,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitEvalContext.js","src/circuit/CircuitStats.js")).CircuitEvalContext,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/circuit/CircuitStats.js")).CircuitShaders,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/circuit/CircuitStats.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetTextureUtil.js","src/circuit/CircuitStats.js")).KetTextureUtil,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/circuit/CircuitStats.js")).Controls,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/CircuitStats.js")).DetailedError,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/circuit/CircuitStats.js")).Matrix,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/circuit/CircuitStats.js")).Shaders,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/circuit/CircuitStats.js")).Serializer,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/CircuitStats.js")).Util,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/fallback.js","src/circuit/CircuitStats.js")).notifyAboutRecoveryFromUnexpectedError,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitComputeUtil.js","src/circuit/CircuitStats.js")).advanceStateWithCircuit,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/circuit/CircuitStats.js")).currentShaderCoder,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/circuit/CircuitStats.js")).WglTextureTrader,g=function(){function e(e,t,r,n,i,a){this.circuitDefinition=e,this.time=t,this._survivalRates=r,this._qubitDensities=n,this.finalState=i,this._customStatsProcessed=a}return $traceurRuntime.createClass(e,{qubitDensityMatrix:function(e,t){if(t<0)throw new o("Bad wireIndex",{wireIndex:t,colIndex:e});if(e<0||t>=this.circuitDefinition.numWires){if(t>=this.circuitDefinition.numWires&&this.qubitDensityMatrix(e,0).hasNaN())return u.zero(2,2).times(NaN);var r=new Float32Array(8);return r[0]=1,new u(2,2,r)}var n=Math.min(e,this._qubitDensities.length-1);return n<0||t>=this._qubitDensities[n].length?u.zero(2,2).times(NaN):this._qubitDensities[n][t]},survivalRate:function(e){return(e=Math.min(e,this._survivalRates.length-1))<0?1:this._survivalRates[e]},customStatsForSlot:function(e,t){var r=e+":"+t;return this._customStatsProcessed.has(r)?this._customStatsProcessed.get(r):void 0},controlledWireProbabilityJustAfter:function(e,t){return this.qubitDensityMatrix(t,e).rawBuffer()[6]},withTime:function(t){return new e(this.circuitDefinition,t,this._survivalRates,this._qubitDensities,this.finalState,this._customStatsProcessed)}},{withNanDataFromCircuitAtTime:function(t,r){return new e(t,r,[1],[],t.numWires<=n.MAX_SIMULATION_WIRE_COUNT?u.zero(1,1<<t.numWires).times(NaN):void 0,new Map)},fromCircuitAtTime:function(t,r){if(t.numWires>n.MAX_SIMULATION_WIRE_COUNT)return e.withNanDataFromCircuitAtTime(t,r);try{return e._fromCircuitAtTime_noFallback(t,r)}catch(n){return d("Defaulted to NaN results. Computing circuit values failed.",{circuitDefinition:c.toJson(t)},n),e.withNanDataFromCircuitAtTime(t,r)}},decohereMeasuredBitsInDensityMatrix:function(e,t){if(0===t)return e;for(var r=new Float32Array(e.rawBuffer()),n=e.width(),i=0;i<n;i++)for(var a=0;a<n;a++)if(0!=((i^a)&t)){var o=2*(i*n+a);r[o]=0,r[o+1]=0}return new u(n,n,r)},scatterAndDecohereDensities:function(t,r,n,i,a){for(var o=u.zero(1<<n,1<<n).times(NaN),s=0,c=[],l=0;l<r-n+1;l++)0==(a&1<<l)?c.push(o):c.push(e.decohereMeasuredBitsInDensityMatrix(t[s++],i>>l&(1<<n)-1));return c},_extractColumnQubitStatsFromPixelDatas:function(t,r){for(var n=[],a=0;a<r.length;a++){var o=a===t.columns.length?-1:t.colDesiredSingleQubitStatsMask(a);n.push(e.scatterAndDecohereDensities(i.pixelsToQubitDensityMatrices(r[a]),t.numWires,1,t.colIsMeasuredMask(a),o))}return n},_extractColumnSurvivalRateStatsFromPixelDatas:function(e){for(var t=1,r=[],n=0;n<e.length;n++)e[n].length>0&&(t=e[n][0]),r.push(t);return r},_fromCircuitAtTime_noFallback:function(n,o){var u=(n=n.withMinimumWireCount()).numWires,c=new h(r.classicalState(0).toVec2Texture(u)),d=r.controlMask(a.NONE).toBoolTexture(u),g=m(new t(o,0,u,a.NONE,d,c,new Map),n,!0),p=g.colQubitDensities,v=g.colNorms,y=g.customStats,b=g.customStatsMap;d.deallocByDepositingInPool("controlTex in _fromCircuitAtTime_noFallback"),f().vec2.needRearrangingToBeInVec4Format&&c.shadeHalveAndTrade(s.packVec2IntoVec4);var R=l.objectifyArrayFunc(i.mergedReadFloats)({output:c.currentTexture,colQubitDensities:p,colNorms:v,customStats:y}),w=e._extractColumnQubitStatsFromPixelDatas(n,R.colQubitDensities),M=e._extractColumnSurvivalRateStatsFromPixelDatas(R.colNorms),_=i.pixelsToAmplitudes(R.output,0===M.length?1:M[M.length-1]),x=new Map,S=!0,T=!1,A=void 0;try{for(var C=void 0,$=b[Symbol.iterator]();!(S=(C=$.next()).done);S=!0){var j=C.value,E=j.col,I=j.row,G=j.out,P=n.gateInSlot(E,I).customStatPostProcesser||function(e){return e};x.set(E+":"+I,P(R.customStats[G],n,E,I))}}catch(e){T=!0,A=e}finally{try{S||null==$.return||$.return()}finally{if(T)throw A}}return new e(n,o,M,w,_,x)}})}();return g.EMPTY=g.withNanDataFromCircuitAtTime(e.EMPTY,0),{get CircuitStats(){return g}}}),$traceurRuntime.registerModule("src/circuit/Controls.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/Controls.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/circuit/Controls.js")).Seq,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/Controls.js")).Util,n=function(){function n(t,r){if(0!=(r&~t))throw new e("Desired un-included bits",{inclusionMask:t,desiredValueMask:r});this.inclusionMask=t,this.desiredValueMask=r}return $traceurRuntime.createClass(n,{isEqualTo:function(e){return e instanceof n&&this.inclusionMask===e.inclusionMask&&this.desiredValueMask===e.desiredValueMask},toString:function(){var e=this;return 0===this.inclusionMask?"No Controls":"Controls: ...__"+t.naturals().takeWhile(function(t){return 1<<t<=e.inclusionMask}).map(this.desiredValueFor.bind(this)).map(function(e){return void 0===e?"_":e?"1":"0"}).reverse().join("")},allowsState:function(e){return(this.inclusionMask&e)===this.desiredValueMask},desiredValueFor:function(e){if(0!=(this.inclusionMask&1<<e))return 0!=(this.desiredValueMask&1<<e)},includedBitCount:function(){return this.inclusionMask<0?1/0:r.numberOfSetBits(this.inclusionMask)},and:function(t){if((t.desiredValueMask&this.inclusionMask)!=(this.desiredValueMask&t.inclusionMask))throw new e("Contradictory controls.",{this:this,other:t});return new n(this.inclusionMask|t.inclusionMask,this.desiredValueMask|t.desiredValueMask)},shift:function(e){return new n(this.inclusionMask<<e,this.desiredValueMask<<e)}},{bit:function(t,r){if(t<0)throw new e("Out of range",{bitIndex:t});return new n(1<<t,r?1<<t:0)}})}();return n.NONE=new n(0,0),{get Controls(){return n}}}),$traceurRuntime.registerModule("src/circuit/CustomGateSet.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/CustomGateSet.js")).DetailedError,t=function(){function t(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.gates=e}return $traceurRuntime.createClass(t,{withGate:function(r){if(!r.serializedId.startsWith("~"))throw new e("Custom gates' serialized id must start with '~'.",{id:r.serializedId,gate:r});if(this.findGateWithSerializedId(r.serializedId))throw new e("Duplicate serialized id.",{gate:r});return new(Function.prototype.bind.apply(t,$traceurRuntime.spread([null],this.gates,[r])))},findGateWithSerializedId:function(e){var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this.gates[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;if(o.serializedId===e)return o}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}},{})}();return{get CustomGateSet(){return t}}}),$traceurRuntime.registerModule("src/circuit/Gate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/Gate.js")).DetailedError,t=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GateDrawParams.js","src/circuit/Gate.js")).GateDrawParams,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/circuit/Gate.js")).Complex),r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/circuit/Gate.js")).Matrix,n=function(){function t(){this.symbol="",this.serializedId="",this.name="",this.blurb="",this.width=1,this.height=1,this.param=void 0,this.customDrawer=void 0,this.onClickGateFunc=void 0,this.tag=void 0,this.customBeforeOperation=void 0,this.customOperation=void 0,this.customAfterOperation=void 0,this.customStatTexturesMaker=void 0,this.customStatPostProcesser=void 0,this.gateFamily=[this],this.interestedInControls=!0,this._stableDuration=void 0,this._knownMatrix=void 0,this._knownMatrixFunc=void 0,this._hasNoEffect=!1,this._effectPermutesStates=void 0,this._effectCreatesSuperpositions=void 0,this.isControlWireSource=!1,this.knownCircuit=void 0,this.knownCircuitNested=void 0,this._requiredContextKeys=[],this.isSingleQubitDisplay=!1,this._controlBit=void 0,this._isDefinitelyUnitary=!1,this.customColumnContextProvider=function(e,t){return[]},this.isContextTemporary=!0,this.customDisableReasonFinder=function(e){},this.knownBitPermutationFunc=void 0,this.knownPhaseTurnsFunc=void 0,this.knownPermutationFuncTakingInputs=void 0,this._showAsReachesOtherWires=!1}return $traceurRuntime.createClass(t,{_copy:function(){var e=new t;return e.symbol=this.symbol,e.name=this.name,e.blurb=this.blurb,e.serializedId=this.serializedId,e.onClickGateFunc=this.onClickGateFunc,e.tag=this.tag,e.param=this.param,e.customDrawer=this.customDrawer,e.interestedInControls=this.interestedInControls,e.customBeforeOperation=this.customBeforeOperation,e.knownBitPermutationFunc=this.knownBitPermutationFunc,e.customOperation=this.customOperation,e.customAfterOperation=this.customAfterOperation,e.customStatTexturesMaker=this.customStatTexturesMaker,e.customStatPostProcesser=this.customStatPostProcesser,e.width=this.width,e.height=this.height,e.isSingleQubitDisplay=this.isSingleQubitDisplay,e._knownMatrix=this._knownMatrix,e.knownCircuit=this.knownCircuit,e._showAsReachesOtherWires=this._showAsReachesOtherWires,e.isContextTemporary=this.isContextTemporary,e.knownCircuitNested=this.knownCircuitNested,e._requiredContextKeys=this._requiredContextKeys,e._knownMatrixFunc=this._knownMatrixFunc,e._stableDuration=this._stableDuration,e._hasNoEffect=this._hasNoEffect,e._effectPermutesStates=this._effectPermutesStates,e._effectCreatesSuperpositions=this._effectCreatesSuperpositions,e._affectsOtherWires=this._affectsOtherWires,e._controlBit=this._controlBit,e.isControlWireSource=this.isControlWireSource,e._isDefinitelyUnitary=this._isDefinitelyUnitary,e.knownPhaseTurnsFunc=this.knownPhaseTurnsFunc,e.knownPermutationFuncTakingInputs=this.knownPermutationFuncTakingInputs,e.customColumnContextProvider=this.customColumnContextProvider,e.customDisableReasonFinder=this.customDisableReasonFinder,e},withParam:function(e){var t=this._copy();return t.param=e,t},getUnmetContextKeys:function(){var e=new Set(this._requiredContextKeys);if(void 0!==this.knownCircuit){var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this.knownCircuit.getUnmetContextKeys()[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e.add(o)}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}return e},shouldShowAsHavingGlobalEffect:function(){return this._showAsReachesOtherWires||!this._isDefinitelyUnitary},canChangeInSize:function(){return this.gateFamily.length>1},canIncreaseInSize:function(){var e=this;return!this.gateFamily.every(function(t){return t.height!==e.height+1})},canDecreaseInSize:function(){var e=this;return!this.gateFamily.every(function(t){return t.height!==e.height-1})},knownMatrixAt:function(e){return void 0!==this._knownMatrix?this._knownMatrix:void 0!==this._knownMatrixFunc?this._knownMatrixFunc(e):void 0},isControl:function(){return void 0!==this._controlBit},controlBit:function(){return this._controlBit},effectMightPermutesStates:function(){return void 0!==this._effectPermutesStates?this._effectPermutesStates:void 0===this._knownMatrix||!this._knownMatrix.isDiagonal()},effectMightCreateSuperpositions:function(){return void 0!==this._effectCreatesSuperpositions?this._effectCreatesSuperpositions:void 0===this._knownMatrix||!this._knownMatrix.isPhasedPermutation()},definitelyHasNoEffect:function(){return this._hasNoEffect},isDefinitelyUnitary:function(){return this._isDefinitelyUnitary},stableDuration:function(){return void 0!==this._stableDuration?this._stableDuration:void 0!==this._knownMatrix||this._hasNoEffect?1/0:0},toString:function(){return"Gate("+this.symbol+")"}},{fromKnownMatrix:function(n,i){var a=void 0!==arguments[2]?arguments[2]:"",o=void 0!==arguments[3]?arguments[3]:"";if(!(i instanceof r))throw new e("Bad matrix.",{symbol:n,matrix:i,name:a,blurb:o});var u=new t;return u.symbol=n,u.serializedId=n,u.name=a,u.blurb=o,u._isDefinitelyUnitary=i.isUnitary(.01),u._hasNoEffect=i.isIdentity(),u._stableDuration=1/0,u._knownMatrix=i,u},buildFamily:function(e,t,r){for(var n=[],a=e;a<=t;a++){var o=new i;o.setHeight(a),r(a,o),o.gate.gateFamily=n,n.push(o.gate)}return{all:n,ofSize:function(e){var t=!0,r=!1,i=void 0;try{for(var a=void 0,o=n[Symbol.iterator]();!(t=(a=o.next()).done);t=!0){var u=a.value;if(u.height===e)return u}}catch(e){r=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(r)throw i}}}}}})}(),i=function(){return $traceurRuntime.createClass(function(){this.gate=new n},{setSerializedIdAndSymbol:function(e){return this.gate.symbol=e,this.gate.serializedId=e,this},setSymbol:function(e){return this.gate.symbol=e,this},setSerializedId:function(e){return this.gate.serializedId=e,this},setTitle:function(e){return this.gate.name=e,this},setBlurb:function(e){return this.gate.blurb=e,this},setHeight:function(e){return this.gate.height=e,this},setWidth:function(e){return this.gate.width=e,this},setDrawer:function(e){return this.gate.customDrawer=e,this},setOnClickGateFunc:function(e){return this.gate.onClickGateFunc=e,this},setKnownEffectToMatrix:function(t){if(!(t instanceof r))throw new e("Bad matrix.",{matrix:t});return this.gate._isDefinitelyUnitary=t.isUnitary(.01),this.gate._hasNoEffect=t.isIdentity(),this.gate._stableDuration=1/0,this.gate._knownMatrix=t,this},setKnownEffectToPermutation:function(e){var t=this;return this.gate.knownPermutationFuncTakingInputs=e,this.gate._knownMatrixFunc=function(n){return r.generateTransition(1<<t.gate.height,e)},this.gate._stableDuration=1/0,this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!0,this.gate._effectCreatesSuperpositions=!1,this.gate._isDefinitelyUnitary=!0,this},setKnownEffectToBitPermutation:function(e){return this.gate.knownBitPermutationFunc=e,this.gate._isDefinitelyUnitary=!0,this.gate._stableDuration=1/0,this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!0,this.gate._effectCreatesSuperpositions=!1,this},setKnownEffectToTimeVaryingPermutation:function(e){var t=this.gate;return t._stableDuration=0,t._knownMatrixFunc=function(n){return r.generateTransition(1<<t.height,function(t){return e(n,t)})},t._hasNoEffect=!1,t._effectPermutesStates=!0,t._effectCreatesSuperpositions=!1,t._isDefinitelyUnitary=!0,this},setKnownEffectToParametrizedPermutation:function(e){var t=this.gate;return t.knownPermutationFuncTakingInputs=e,t._knownMatrixFunc=void 0,t._stableDuration=1/0,t._hasNoEffect=!1,t._effectPermutesStates=!0,t._effectCreatesSuperpositions=!1,t._isDefinitelyUnitary=!0,this},setKnownEffectToPhaser:function(e){var n=this;return this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!1,this.gate._effectCreatesSuperpositions=!1,this.gate._isDefinitelyUnitary=!0,this.gate._stableDuration=1/0,this.gate.knownPhaseTurnsFunc=e,this.gate._knownMatrixFunc=function(){return r.generateDiagonal(1<<n.gate.height,function(r){return t.polar(1,2*Math.PI*e(r))})},this},setTooltipMatrixFunc:function(e){return this.gate._knownMatrixFunc=function(t){return e()},this.gate._stableDuration=1/0,this},setKnownEffectToCircuit:function(e){return this.gate.knownCircuit=e,this.gate.knownCircuitNested=e.withDisabledReasonsForEmbeddedContext(0,new Map),this.gate._isDefinitelyUnitary=e.hasOnlyUnitaryGates(),this.gate._stableDuration=e.stableDuration(),this.gate.height=e.numWires,this},setEffectToTimeVaryingMatrix:function(e){return this.gate._stableDuration=0,this.gate._knownMatrixFunc=e,this.gate._hasNoEffect=!1,this},setActualEffectToUpdateFunc:function(t){if(void 0!==t&&"function"!=typeof t)throw new e("Bad customOperation",{circuitUpdateFunc:t});return this.gate.customOperation=t,this},setActualEffectToShaderProvider:function(e){return this.setActualEffectToUpdateFunc(function(t){return t.applyOperation(e)})},promiseEffectOnlyPermutesAndPhases:function(){return this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!0,this.gate._effectCreatesSuperpositions=!1,this.gate._isDefinitelyUnitary=!0,this},promiseEffectIsDiagonal:function(){return this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!1,this.gate._effectCreatesSuperpositions=!1,this},promiseEffectOnlyPhases:function(){return this.gate._hasNoEffect=!1,this.gate._effectPermutesStates=!1,this.gate._effectCreatesSuperpositions=!1,this.gate._isDefinitelyUnitary=!0,this},promiseEffectIsUnitary:function(){return this.gate._isDefinitelyUnitary=!0,this},promiseEffectIsStable:function(){return this.gate._stableDuration=1/0,this},promiseHasNoNetEffectOnStateVector:function(){return this.gate._stableDuration=1/0,this.gate._hasNoEffect=!0,this.gate._isDefinitelyUnitary=!0,this.gate._effectPermutesStates=!1,this.gate._effectCreatesSuperpositions=!1,this},promiseHasNoNetEffectOnStateVectorButStillRequiresDynamicRedraw:function(){return this.promiseHasNoNetEffectOnStateVector(),this.gate._stableDuration=0,this},markAsNotInterestedInControls:function(){return this.gate.interestedInControls=!1,this},markAsControlExpecting:function(e){return this.gate._controlBit=e,this.gate.isControlWireSource=!0,this.gate._isDefinitelyUnitary=!0,this.gate.interestedInControls=!1,this},markAsReachingOtherWires:function(){return this.gate._showAsReachesOtherWires=!0,this},markAsDrawerNeedsSingleQubitDensityStats:function(){return this.gate.isSingleQubitDisplay=!0,this},setRequiredContextKeys:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.gate._requiredContextKeys=e,this},setContextProvider:function(e){return this.gate.customColumnContextProvider=e,this.gate.isContextTemporary=!0,this},setStickyContextProvider:function(e){return this.gate.customColumnContextProvider=e,this.gate.isContextTemporary=!1,this},setSetupCleanupEffectsToShaderProviders:function(e,t){return this.setSetupCleanupEffectToUpdateFunc(void 0===e?void 0:function(t){return t.applyOperation(e)},void 0===t?void 0:function(e){return e.applyOperation(t)})},setSetupCleanupEffectToUpdateFunc:function(t,r){if(void 0!==t&&"function"!=typeof t)throw new e("Bad beforeColumnUpdateFunc",{customOperation:customOperation});if(void 0!==r&&"function"!=typeof r)throw new e("Bad afterColumnUpdateFunc",{customOperation:customOperation});return this.gate.customBeforeOperation=t,this.gate.customAfterOperation=r,this},setExtraDisableReasonFinder:function(e){return this.gate.customDisableReasonFinder=e,this},setStatTexturesMaker:function(e){return this.gate.customStatTexturesMaker=e,this},setStatPixelDataPostProcessor:function(e){return this.gate.customStatPostProcesser=e,this},setTag:function(e){return this.gate.tag=e,this}},{})}();return{get Gate(){return n},get GateBuilder(){return i}}}),$traceurRuntime.registerModule("src/circuit/GateCheckArgs.js",[],function(){"use strict";var e=function(){return $traceurRuntime.createClass(function(e,t,r,n,i,a){this.gate=e,this.innerColumn=t,this.outerRow=r,this.measuredMask=n,this.context=i,this.isNested=a},{},{})}();return{get GateCheckArgs(){return e}}}),$traceurRuntime.registerModule("src/circuit/GateColumn.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/GateColumn.js")).DetailedError,t=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/circuit/GateColumn.js")).Gate,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateCheckArgs.js","src/circuit/GateColumn.js")).GateCheckArgs),r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/circuit/GateColumn.js")).Gates,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/circuit/GateColumn.js")),i=n.seq,a=(n.Seq,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/GateColumn.js")).Util),o=function(){function n(e){this.gates=e}return $traceurRuntime.createClass(n,{isEqualTo:function(e){return this===e||e instanceof n&&i(this.gates).isEqualTo(i(e.gates),a.STRICT_EQUALITY)},stableDuration:function(){var e;return(e=Math).min.apply(e,$traceurRuntime.spread([1/0],this.gates.filter(function(e){return void 0!==e}).map(function(e){return e.stableDuration()})))},isEmpty:function(){return this.gates.every(function(e){return void 0===e})},hasControl:function(e){return this.hasCoherentControl(e)||this.hasMeasuredControl(e)},hasCoherentControl:function(e){for(var t=0;t<this.gates.length;t++)if(0==(e&1<<t)&&void 0!==this.gates[t]&&this.gates[t].isControl())return!0;return!1},hasMeasuredControl:function(e){for(var t=0;t<this.gates.length;t++)if(0!=(e&1<<t)&&void 0!==this.gates[t]&&this.gates[t].definitelyHasNoEffect()&&this.gates[t].isControl())return!0;return!1},_disabledReason:function(e,r,i,a,o){var u=this.gates[r];if(void 0!==u){var s=new t(u,this,i+r,e,a,o);return u.customDisableReasonFinder(s)||n._disabledReason_inputs(s)||this._disabledReason_controlInside(r)||this._disabledReason_remixing(r,e)||this._disabledReason_overlappingTags(i,r)}},_disabledReason_overlappingTags:function(e,t){var r=new Set(this.gates[t].customColumnContextProvider(e+t,this.gates[t]).map(function(e){return e.key}));if(0!==r.length)for(var n=0;n<t;n++){var i=this.gates[n],a=!0,o=!1,u=void 0;try{for(var s=void 0,c=(void 0===i?[]:i.customColumnContextProvider(e+n,i))[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value.key;if(r.has(l))return"already\ndefined"}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}}},_disabledReason_remixing:function(e,t){var r=this.gates[e],n=(1<<r.height)-1<<e,i=n&t;if(0!==i){if(r.effectMightCreateSuperpositions())return"no\nremix\n(sorry)";if(r.effectMightPermutesStates()){if(i!==n&&(void 0===r.knownBitPermutationFunc||this.hasMeasuredControl(t)))return"no\nremix\n(sorry)";if(this.hasCoherentControl(t))return"no\nremix\n(sorry)"}}},hasGatesWithGlobalEffects:function(){for(var e=0;e<this.gates.length;e++){var t=this.gates[e];if(void 0!==t&&t.shouldShowAsHavingGlobalEffect())return!0}return!1},indexOfNonUnitaryGate:function(){for(var e=0;e<this.gates.length;e++){var t=this.gates[e];if(void 0!==t&&!t.isDefinitelyUnitary())return e}},_disabledReason_controlInside:function(e){for(var t=this.gates[e],r=1;r<t.height&&e+r<this.gates.length;r++)if(void 0!==this.gates[e+r]&&this.gates[e+r].isControl())return"control\ninside"},minimumRequiredWireCount:function(){for(var e=0,t=0;t<this.gates.length;t++)void 0!==this.gates[t]&&(e=Math.max(e,this.gates[t].height+t));return e},maximumGateWidth:function(){var e=-1/0,t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this.gates[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;void 0!==o&&(e=Math.max(e,o.width))}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}return e},perRowDisabledReasons:function(e,t,r,n,i){for(var o=a.mergeMaps(r,n),u=new Map(n),s=this.gates.length-1;s>=0;s--){var c=this.gates[s];if(void 0!==c){var l=!0,d=!1,m=void 0;try{for(var f=void 0,h=c.customColumnContextProvider(s+t,c)[Symbol.iterator]();!(l=(f=h.next()).done);l=!0){var g=f.value,p=g.key,v=g.val;o.set(p,v),c.isContextTemporary||u.set(p,v)}}catch(e){d=!0,m=e}finally{try{l||null==h.return||h.return()}finally{if(d)throw m}}}}for(var y=[],b=0;b<this.gates.length;b++)y.push(this._disabledReason(e,b,t,o,i));return{allReasons:y,stickyCtx:u}},_updateMeasureMask_gateStep:function(e,t,i){if(void 0===i[t]){var a=this.gates[t];if(void 0!==a)if(a!==r.Special.Measurement){var o=a===r.PostSelectionGates.PostSelectOn||a===r.PostSelectionGates.PostSelectOff||a===r.Detector;this.hasControl()||!o?(n._updateMeasureMask_swapGate(a,e,t),n._updateMeasureMask_customPermute(a,e,t)):e.measureMask&=~(1<<t)}else e.measureMask|=1<<t}},nextMeasureMask:function(e,t){for(var r={measureMask:e,earlierRowWithSwapGate:void 0},n=0;n<this.gates.length;n++)this._updateMeasureMask_gateStep(r,n,t);return r.measureMask},withGatesAdded:function(t,r){if(!Number.isInteger(t)||t<0||t>this.gates.length-r.gates.length)throw new e("Bad start index",{baseCol:this,startIndex:t,insertedCol:r});for(var i=this.gates.map(function(e){return e}),a=0;a<r.gates.length;a++)i[t+a]=r.gates[a];return new n(i)}},{empty:function(e){return new n(new Array(e).fill(void 0))},_disabledReason_inputs:function(e){var t=[],r=!0,i=!1,a=void 0;try{for(var o=void 0,u=e.gate.getUnmetContextKeys()[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value;s.startsWith("Input Range ")&&e.context.has(s)&&t.push(e.context.get(s))}}catch(e){i=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw a}}return n._disabledReason_inputs_missing(e)||n._disabledReason_inputs_inside(e,t)||n._disabledReason_inputs_coherenceMismatch(e,t)},_disabledReason_inputs_missing:function(e){var t=[],r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e.gate.getUnmetContextKeys()[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value,s=u.replace("Input Range ","Input Default ").replace("Input NO_DEFAULT Range ","Input Range ");e.context.has(u)||e.context.has(s)||e.isNested||t.push(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}if(t.length>0)return"Need\nInput\n "+t.map(function(e){return e.replace("Input NO_DEFAULT Range ","").replace("Input Range ","")}).join(", ")},_disabledReason_inputs_inside:function(e,t){var r=e.outerRow,n=!0,i=!1,a=void 0;try{for(var o=void 0,u=t[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=s.offset;if(c+s.length>r&&r+e.gate.height>c)return"input\ninside"}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}},_disabledReason_inputs_coherenceMismatch:function(e,t){var r=e.outerRow;if(e.gate.effectMightPermutesStates()&&0!=(e.measuredMask>>r&(1<<e.gate.height)-1)){var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=t[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=s.offset,l=s.length;if(0!=(~e.measuredMask>>c&(1<<l)-1))return"no\nremix\n(sorry)"}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}}},_updateMeasureMask_swapGate:function(e,t,n){if(e===r.Special.SwapHalf)if(void 0!==t.earlierRowWithSwapGate){var i=1<<t.earlierRowWithSwapGate,a=n-t.earlierRowWithSwapGate,o=1<<n;t.measureMask=t.measureMask&~(i|o)|(t.measureMask&i)<<a|(t.measureMask&o)>>a,t.earlierRowWithSwapGate=void 0}else t.earlierRowWithSwapGate=n},_updateMeasureMask_customPermute:function(e,t,r){if(void 0!==e.knownBitPermutationFunc){var n=(1<<e.height)-1<<r,i=t.measureMask&n;t.measureMask&=~n;for(var a=0;a<e.height;a++)if(0!=(i&1<<r+a)){var o=1<<r+e.knownBitPermutationFunc(a);t.measureMask|=o}}}})}();return{get GateColumn(){return o}}}),$traceurRuntime.registerModule("src/circuit/GateShaders.js",[],function(){"use strict";function e(e,r){var i,a,o;if(2!==r.width()||2!==r.height())throw new t("Not a single-qubit operation.",{matrix:r});var s=(a=r.rawBuffer()[Symbol.iterator](),(o=a.next()).done?void 0:o.value),c=(o=a.next()).done?void 0:o.value,l=(o=a.next()).done?void 0:o.value,d=(o=a.next()).done?void 0:o.value,m=(o=a.next()).done?void 0:o.value,f=(o=a.next()).done?void 0:o.value,g=(o=a.next()).done?void 0:o.value,p=(o=a.next()).done?void 0:o.value;e.applyOperation((i=h).withArgs.apply(i,$traceurRuntime.spread(n(e),[u.vec2("a",s,c),u.vec2("b",l,d),u.vec2("c",m,f),u.vec2("d",g,p)])))}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/GateShaders.js")).DetailedError,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/circuit/GateShaders.js")),n=r.ketArgs,i=r.ketShader,a=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/circuit/GateShaders.js")).Matrix,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/circuit/GateShaders.js")).Shaders),o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/GateShaders.js")).Util,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/circuit/GateShaders.js")).WglArg,s=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/circuit/GateShaders.js")).WglConfiguredShader,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/circuit/GateShaders.js"))),c=s.Inputs,l=s.Outputs,d=s.currentShaderCoder,m=s.makePseudoShaderWithInputsAndOutputAndCode,f=function(){return $traceurRuntime.createClass(function(){},{},{})}(),h=i("uniform vec2 a, b, c, d;","return cmul(inp(0.0), a+(c-a)*out_id) + cmul(inp(1.0), b+(d-b)*out_id);",1),g=function(e){return i("uniform vec4 coefs["+(1<<2*e-1)+"];","\n int row = int(out_id);\n vec2 t = vec2(0.0, 0.0);\n for (int d = 0; d < "+(1<<e)+"; d++) {\n // Can't index by row, since it's not a constant, so we do a const brute force loop searching for it.\n if (d == row) {\n for (int k = 0; k < "+(1<<e-1)+"; k++) {\n vec4 u = coefs[d*"+(1<<e-1)+" + k];\n t += cmul(inp(float(k*2)), u.xy);\n t += cmul(inp(float(k*2+1)), u.zw);\n }\n }\n }\n return t;\n ",e)},p=[void 0,void 0,g(2),g(3),function(e){return i("","\n vec2 t = vec2(0.0, 0.0);\n for (int k = 0; k < "+(1<<e)+"; k++) {\n t += cmul(inp(float(k)),\n read_coefs(out_id * "+(1<<e)+".0 + float(k)));\n }\n return t;\n ",e,[c.vec2("coefs")])}(4)];f.applyMatrixOperation=function(r,i){var s,c;if(!o.isPowerOf2(i.width()))throw new t("Matrix size isn't a power of 2.",{ctx:r,matrix:i});if(2!==i.width()){var l=Math.round(Math.log2(i.width()));if(l<=3)r.applyOperation((s=p[l]).withArgs.apply(s,$traceurRuntime.spread(n(r),[u.vec4_array("coefs",i.rawBuffer())])));else{if(!(l<=4))throw new t("Matrix is past 4 qubits. Too expensive.",{ctx:r,matrix:i});var m=a.data(d().vec2.dataToPixels(i.rawBuffer())).toVec2Texture(2*l);try{r.applyOperation((c=p[l]).withArgs.apply(c,$traceurRuntime.spread([m],n(r))))}finally{m.deallocByDepositingInPool()}}}else e(r,i)},f.cycleAllBits=function(e,t){var r=d().vec2.arrayPowerSizeOfTexture(e);return v(e,u.float("shiftAmount",1<<o.properMod(-t,r)))};var v=m([c.vec2("input")],l.vec2(),"\n uniform float shiftAmount;\n\n vec2 outputFor(float k) {\n float span = len_input();\n float shiftedState = k * shiftAmount;\n float cycledState = mod(shiftedState, span) + floor(shiftedState / span);\n return read_input(cycledState);\n }");f.cycleAllBitsFloat=function(e,t){var r=d().vec2.arrayPowerSizeOfTexture(e);return y(e,u.float("shiftAmount",1<<o.properMod(-t,r)))};var y=m([c.float("input")],l.float(),"\n uniform float shiftAmount;\n\n float outputFor(float k) {\n float span = len_input();\n float shiftedState = k * shiftAmount;\n float cycledState = mod(shiftedState, span) + floor(shiftedState / span);\n return read_input(cycledState);\n }");return{get GateShaders(){return f}}}),$traceurRuntime.registerModule("src/circuit/KetShaderUtil.js",[],function(){"use strict";function e(e){var t,i=arguments[1],a=void 0!==arguments[2]?arguments[2]:[],o=[e.stateTrader.currentTexture,e.controlsTexture,n.float("_ketgen_step",1<<e.row)];void 0!==i&&o.push(n.float("span",1<<i));var u=!0,s=!1,c=void 0;try{for(var l=void 0,d=a[Symbol.iterator]();!(u=(l=d.next()).done);u=!0){var m=l.value;(t=o).push.apply(t,$traceurRuntime.spread(r(e,m)))}}catch(e){s=!0,c=e}finally{try{u||null==d.return||d.return()}finally{if(s)throw c}}return o}function t(e){return"\n //////// INPUT GATE "+e+" ////////\n uniform float _gen_input_default_"+e+";\n uniform float _gen_input_offset_"+e+";\n uniform float _gen_input_span_"+e+";\n \n float read_input_"+e+"() {\n return _gen_input_span_"+e+" == 0.0\n ? _gen_input_default_"+e+"\n : mod(floor(full_out_id / _gen_input_offset_"+e+"), _gen_input_span_"+e+");\n }"}function r(e,t){var r=0,i=-1,a=e.customContextFromGates.get("Input Default "+t)||0,o=e.customContextFromGates.get("Input Range "+t);return void 0!==o&&(r=o.offset,i=o.length),[n.float("_gen_input_default_"+t,a),n.float("_gen_input_offset_"+t,1<<r),n.float("_gen_input_span_"+t,-1===i?0:1<<i)]}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/circuit/KetShaderUtil.js")).WglArg,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/circuit/KetShaderUtil.js")),a=i.makePseudoShaderWithInputsAndOutputAndCode,o=i.Inputs,u=i.Outputs,s=function(e,t){var r=void 0!==arguments[2]?arguments[2]:null,n=void 0!==arguments[3]?arguments[3]:[];return{withArgs:a($traceurRuntime.spread(n,[o.vec2("ketgen_ket"),o.bool("ketgen_control")]),u.vec2(),"\n uniform float _ketgen_step;\n "+(null===r?"uniform float span;":"")+"\n float _ketgen_off;\n float full_out_id;\n\n "+(t.match(/\bcmul\b/)?"vec2 cmul(vec2 c1, vec2 c2) { return mat2(c1.x, c1.y, -c1.y, c1.x) * c2; }":"")+"\n "+(t.match(/\binp\b/)?"vec2 inp(float k) { return read_ketgen_ket(_ketgen_off + _ketgen_step*k); }":"")+"\n\n "+e+"\n\n vec2 _ketgen_output_for(float out_id, vec2 amp) {\n "+t+"\n }\n\n vec2 outputFor(float k) {\n full_out_id = k;\n\n float relevant_out_id = mod(floor(full_out_id / _ketgen_step), "+(null===r?"span":(1<<r)+".0")+");\n _ketgen_off = full_out_id - relevant_out_id*_ketgen_step;\n\n float c = read_ketgen_control(full_out_id);\n vec2 vc = read_ketgen_ket(full_out_id);\n vec2 vt = _ketgen_output_for(relevant_out_id, vc);\n return (1.0-c)*vc + c*vt;\n }")}},c=function(e,t){var r=void 0!==arguments[2]?arguments[2]:null;return s(e+"float _ketgen_input_for(float out_id) { "+t+" }","return inp(_ketgen_input_for(out_id));",r)},l=function(e,t){var r=void 0!==arguments[2]?arguments[2]:null;return s(e+"\n float _ketgen_phase_for(float out_id) {\n "+t+"\n }\n ","\n float angle = _ketgen_phase_for(out_id);\n return cmul(amp, vec2(cos(angle), sin(angle)));\n ",r)};return{get ketArgs(){return e},get ketShader(){return s},get ketShaderPermute(){return c},get ketShaderPhase(){return l},get ketInputGateShaderCode(){return t},get ketInputGateArgs(){return r}}}),$traceurRuntime.registerModule("src/circuit/KetTextureUtil.js",[],function(){"use strict";function e(e,t){if(0===t)throw new i("keptBitMask === 0",{trader:e,keptBitMask:t});var n=h().vec2.arrayPowerSizeOfTexture(e.currentTexture),a=u.numberOfSetBits(t);e.shadeAndTrade(function(e){return r.qubitDensities(e,t)},y.takeVec4Tex(n-1+u.ceilLg2(a)))}function t(e,t){for(var r=u.ceilLg2(t),n=h().vec4.arrayPowerSizeOfTexture(e.currentTexture);n>r;)e.shadeHalveAndTrade(o.sumFoldVec4),n-=1}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/circuit/KetTextureUtil.js")).CircuitShaders,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/circuit/KetTextureUtil.js")).Controls,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/KetTextureUtil.js")).DetailedError,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/circuit/KetTextureUtil.js")).Matrix,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/circuit/KetTextureUtil.js")).Shaders,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/KetTextureUtil.js")).Util,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexture.js","src/circuit/KetTextureUtil.js")).WglTexture,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/circuit/KetTextureUtil.js")),l=c.seq,d=c.Seq,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/circuit/KetTextureUtil.js")),f=m.outputShaderCoder,h=m.currentShaderCoder,g=m.makePseudoShaderWithInputsAndOutputAndCode,p=m.Inputs,v=m.Outputs,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/circuit/KetTextureUtil.js")).WglTexturePool,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/circuit/KetTextureUtil.js")).WglTextureTrader,R=function(){return $traceurRuntime.createClass(function(){},{},{})}();R.tradeTextureForVec2Output=function(e){return h().vec2.needRearrangingToBeInVec4Format&&e.shadeHalveAndTrade(o.packVec2IntoVec4),R.tradeTextureForVec4Output(e)},R.tradeTextureForVec4Output=function(e){if(f()===h()){var t=h().vec4.pixelsToData(e.currentTexture.readPixels());return e.currentTexture.deallocByDepositingInPool("tradeTextureForVec4Output"),t}var r=h().vec4.arrayPowerSizeOfTexture(e.currentTexture)+f().vec4.powerSizeOverhead;e.shadeAndTrade(o.convertVec4CodingForOutput,y.take(r,f().vec4.pixelType));var n=f().vec4.pixelsToData(e.currentTexture.readPixels());return e.currentTexture.deallocByDepositingInPool("tradeTextureForVec4Output"),n},R.mergedReadFloats=function(e){var t=function(e){return 0===e.width?0:1<<h().vec4.arrayPowerSizeOfTexture(e)},n=Math.round(Math.log2(u.ceilingPowerOf2(l(e).map(t).sum()))),i=new b(o.color(0,0,0,0).toVec4Texture(n)),a=0,s=!0,c=!1,d=void 0;try{for(var m=void 0,f=e[Symbol.iterator]();!(s=(m=f.next()).done);s=!0)!function(){var e=m.value;e.width>0&&i.shadeAndTrade(function(t){return r.linearOverlay(a,e,t)}),a+=t(e)}()}catch(e){c=!0,d=e}finally{try{s||null==f.return||f.return()}finally{if(c)throw d}}var g=R.tradeTextureForVec4Output(i),p=[],v=0,y=!0,w=!1,M=void 0;try{for(var _=void 0,x=e[Symbol.iterator]();!(y=(_=x.next()).done);y=!0){var S=_.value,T=t(S)<<2;p.push(g.subarray(v,v+T)),v+=T,S.deallocByDepositingInPool()}}catch(e){w=!0,M=e}finally{try{y||null==x.return||x.return()}finally{if(w)throw M}}return p},R.pixelsToAmplitudes=function(e,t){t<1e-6&&(t=NaN);for(var r=Math.sqrt(t),n=e.length>>1,i=new Float32Array(2*n),o=0;o<e.length;o++)i[o]=e[o]/r;return new a(1,n,i)},R.superpositionToQubitDensities=function(i,a,o){if(0===o)return new s(0,0,h().vec4.pixelType);var c=!a.isEqualTo(n.NONE),l=new b(i);if(l.dontDeallocCurrentTexture(),c){var d=h().vec2.arrayPowerSizeOfTexture(i)-a.includedBitCount();l.shadeAndTrade(function(e){return r.controlSelect(a,e)},y.takeVec2Tex(d))}for(var m=1,f=1;f<=a.inclusionMask;f<<=1)0==(a.inclusionMask&f)?m<<=1:o=o&m-1|(o&~(m-1))>>1;return e(l,o),t(l,u.numberOfSetBits(o)),l.currentTexture},R.pixelsToQubitDensityMatrices=function(e){var t=e.length/4;return d.range(t).map(function(t){var r=e[4*t],n=e[4*t+3],i=r+n;if(i<1e-7||isNaN(i))return new a(2,2,new Float32Array([NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]));var o=e[4*t+1]/i,u=e[4*t+2]/i;return new a(2,2,new Float32Array([r/i,0,o,u,o,-u,n/i,0]))}).toArray()};var w=g([p.vec2("input")],v.float(),"float outputFor(float k) {\n vec2 amp = read_input(k);\n return dot(amp, amp);\n }");return R.superpositionToNorm=function(e,t){if(!t)return new s(0,0,h().vec4.pixelType);var r=new b(e);r.dontDeallocCurrentTexture();var n=h().vec2.arrayPowerSizeOfTexture(e);for(r.shadeAndTrade(w,y.takeVecFloatTex(n));n>0;)n-=1,r.shadeHalveAndTrade(o.sumFoldFloat);return r.shadeAndTrade(o.packFloatIntoVec4,y.takeVec4Tex(0)),r.currentTexture},{get KetTextureUtil(){return R}}}),$traceurRuntime.registerModule("src/circuit/Serializer.js",[],function(){"use strict";function e(e,t,r,n){j=e,C=t,$=r,E=n}function t(e){var t="string"==typeof e?e:e.id;return void 0===t?"":"string"!=typeof t?m(t):t}function r(e){if(void 0===e)throw new Error("Unrecognized gate id, but no matrix specified.");var t=P(e);if(t.width()!==t.height())throw new Error("Gate matrix must be square.");if(t.width()<2||t.width()>16||!w.isPowerOf2(t.width()))throw new Error("Supported gate matrix sizes are 2, 4, 8, and 16.");return t}function n(e){var t=void 0!==arguments[1]?arguments[1]:new d;return e.gates.map(function(e){return void 0===e?1:k(e,t)})}function i(e){for(var t=[],r=0;r<e.gates.length;r++)t.push(k(e.gates[r],new(Function.prototype.bind.apply(d,$traceurRuntime.spread([null],e.gates.slice(0,r))))));return t}function a(e){if(!Array.isArray(e))throw new f("Expected an array of gates.",{json:e});var t=new d,r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;t=t.withGate(z(u,t))}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return t}function o(e){return L===e?U:(L=e,U=u(JSON.parse(e),void 0))}function u(e){var t=arguments[1],r=e.cols,n=t||(void 0===e.gates?new d:a(e.gates));if(!Array.isArray(r))throw new Error("CircuitDefinition json should contain an array of cols. Json: "+m(e));var i=r.map(function(e){return F(e,n)}),o=0,u=!0,c=!1,f=void 0;try{for(var h=void 0,g=i[Symbol.iterator]();!(u=(h=g.next()).done);u=!0){var p=h.value;o=Math.max(o,p.minimumRequiredWireCount())}}catch(e){c=!0,f=e}finally{try{u||null==g.return||g.return()}finally{if(c)throw f}}return o=Math.max(l.MIN_WIRE_COUNT,Math.min(o,l.MAX_WIRE_COUNT)),i=i.map(function(e){return new y($traceurRuntime.spread(e.gates,new Array(Math.max(0,o-e.gates.length)).fill(void 0)).slice(0,o))}),new s(o,i,void 0,void 0,n).withTrailingSpacersIncluded()}var s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/circuit/Serializer.js")).CircuitDefinition,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/circuit/Serializer.js")).Complex,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/circuit/Serializer.js")).Config,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CustomGateSet.js","src/circuit/Serializer.js")).CustomGateSet,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Describe.js","src/circuit/Serializer.js")).describe,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/circuit/Serializer.js")).DetailedError,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/circuit/Serializer.js")).Format,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/circuit/Serializer.js")),p=g.Gate,v=g.GateBuilder,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateColumn.js","src/circuit/Serializer.js")).GateColumn,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/circuit/Serializer.js")).Gates,R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/circuit/Serializer.js")).Matrix,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/circuit/Serializer.js")).Util,M=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/fallback.js","src/circuit/Serializer.js")).notifyAboutRecoveryFromUnexpectedError,_=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Joke_MysteryGate.js","src/circuit/Serializer.js")),x=_.MysteryGateSymbol,S=_.MysteryGateMakerWithMatrix,T=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/circuit/Serializer.js")).seq,A=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitComputeUtil.js","src/circuit/Serializer.js")).setGateBuilderEffectToCircuit,C=void 0,$=void 0,j=void 0,E=void 0,I=function(){return $traceurRuntime.createClass(function(){},{},{toJson:function(e){var t,r,n=arguments[1],i=!0,a=!1,o=void 0;try{for(var u=void 0,s=W[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=(t=u.value[Symbol.iterator](),(r=t.next()).done?void 0:r.value),l=(r=t.next()).done?void 0:r.value;(r=t.next()).done||r.value;if(e instanceof c)return l(e,n)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}throw new Error("Don't know how to convert "+m(e)+" to JSON.")},fromJson:function(e,t){var r,n,i=arguments[2],a=!0,o=!1,u=void 0;try{for(var s=void 0,c=W[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=(r=s.value[Symbol.iterator](),(n=r.next()).done?void 0:n.value),d=((n=r.next()).done||n.value,(n=r.next()).done?void 0:n.value);if(l===e)return d(t,i)}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}throw new Error("Don't know how to deserialize JSON "+m(t)+" into an instance of "+e+".")}})}(),G=function(e){return e.toString(h.MINIFIED)},P=function(e){if("string"!=typeof e)throw new Error("Not a packed matrix string: "+e);return R.parse(e)},k=function(e){var t=void 0!==arguments[1]?arguments[1]:new d,r=b.findKnownGateById(e.serializedId,t);if(r===e)return e.serializedId;if(void 0!==r&&void 0!==r.param)return{id:e.serializedId,arg:e.param};if("Parse Error"===e.name)return e.tag;var n={};if(""!==e.serializedId&&(n.id=e.serializedId),(e.serializedId.startsWith("~")?""!==e.symbol:e.symbol!==e.serializedId)&&(n.name=e.symbol),e.stableDuration()===1/0&&void 0!==e.knownMatrixAt(0))n.matrix=G(e.knownMatrixAt(.25));else{if(void 0===e.knownCircuit)throw new f("Don't known how to serialize gate's function.",{gate:e});n.circuit=B(e.knownCircuit,t)}return n},N=function(e){var r=t(e),n=e.matrix,i=e.circuit,a=e.arg;if(void 0!==a&&(!Number.isInteger(a)||a<0||a>65536))throw new f("Gate arg not int in [0, 2^16].",{json:e});var o=void 0!==e.name?e.name:r.startsWith("~")?"":r;return{id:r,matrix:n,circuit:i,symbol:o,name:r.startsWith("~")?(o||"Custom")+" Gate ["+r.substring(1)+"]":""!==o?o:r,param:a}},O=function(e){var t=r(e.matrix);if(e.id===x)return S(t);var n=Math.round(Math.log2(t.height())),i=""===e.symbol?n:1,a=r(e.matrix),o=(new v).setSerializedId(e.id).setSymbol(e.symbol).setTitle(e.name).setHeight(n).setWidth(i).setDrawer(""===e.symbol?C:a.isIdentity()?j:a.isScaler()?E:void 0).setKnownEffectToMatrix(a);return a.isIdentity()&&o.markAsNotInterestedInControls(),o.gate},D=function(e,t){var r=u(e.circuit,t).withMinimumWireCount();return A(new v,r).setSerializedId(e.id).setSymbol(e.symbol).setTitle(e.name).setDrawer($).gate},z=function(e){var t=void 0!==arguments[1]?arguments[1]:new d,r=N(e);try{if(void 0!==r.matrix)return O(r);if(void 0!==r.circuit)return D(r,t);var n=b.findKnownGateById(r.id,t);if(void 0===n)throw new f("No gate with the id '"+r.id+"'.",{json:e});if(void 0!==r.param){if(void 0===n.param)throw new f("Arg for gate without arg.",{json:e});n=n.withParam(r.param)}return n}catch(t){return M("Defaulted to a do-nothing 'parse error' gate. Failed to understand the json defining a gate.",{gate_json:e},t),(new v).setSerializedIdAndSymbol(r.id).setTitle("Parse Error").setBlurb(m(t)).promiseHasNoNetEffectOnStateVector().setExtraDisableReasonFinder(function(){return"parse\nerror"}).setTag(e).gate}},F=function(e){var t=void 0!==arguments[1]?arguments[1]:new d;if(!Array.isArray(e))throw new Error("GateColumn json should be an array. Json: "+m(e));return new y(e.map(function(e){return 1===e||void 0===e?void 0:z(e,t)}))},B=function(e,t){var r={cols:e.trimEmptyColumnsAtEndIgnoringGateWidths().columns.map(function(r){return n(r,t||e.customGateSet)}).map(function(e){return T(e).skipTailWhile(function(e){return 1===e}).toArray()})};return void 0===t&&e.customGateSet.gates.length>0&&(r.gates=i(e.customGateSet)),r},U=void 0,L=void 0,W=[[c,function(e){return e.toString(h.MINIFIED)},function(e){if("string"==typeof e)return c.parse(e);throw new Error("Not a packed complex string: "+e)}],[p,k,z],[R,G,P],[y,n,F],[s,B,u]];return{get Serializer(){return I},get initSerializer(){return e},get fromJsonText_CircuitDefinition(){return o}}}),$traceurRuntime.registerModule("src/Config.js",[],function(){"use strict";var e=function(){return $traceurRuntime.createClass(function(){},{},{})}();return e.EMPTY_CIRCUIT_TITLE="Quirk: Quantum Circuit Simulator",e.MAX_WIRE_COUNT=1024,e.SIMPLE_SUPERPOSITION_DRAWING_WIRE_THRESHOLD=14,e.MAX_SIMULATION_WIRE_COUNT=16,e.MIN_WIRE_COUNT=2,e.MIN_COL_COUNT=5,e.URL_CIRCUIT_PARAM_KEY="circuit",e.GATE_FILL_COLOR="white",e.HIGHLIGHTED_GATE_FILL_COLOR="#FB7",e.TIME_DEPENDENT_HIGHLIGHT_COLOR="#FFC",e.DISPLAY_GATE_IN_TOOLBOX_FILL_COLOR="#4F4",e.DISPLAY_GATE_BACK_COLOR="#EFE",e.DISPLAY_GATE_FORE_COLOR="#3F3",e.OPERATION_BACK_COLOR="#FFE",e.OPERATION_FORE_COLOR="#FF0",e.SUPERPOSITION_BACK_COLOR="#EFF",e.SUPERPOSITION_MID_COLOR="#8FF",e.SUPERPOSITION_FORE_COLOR="#0BB",e.CYCLE_DURATION_MS=8e3,e.TIME_CACHE_GRANULARITY=196,e.REDRAW_COOLDOWN_MILLIS=10,e.GATE_RADIUS=20,e.WIRE_SPACING=50,e.BACKGROUND_COLOR="white",e.BACKGROUND_COLOR_CIRCUIT="white",e.BACKGROUND_COLOR_TOOLBOX="#CCC",e.TOOLBOX_GATE_SPACING=2,e.TOOLBOX_GROUP_SPACING=24-e.TOOLBOX_GATE_SPACING,e.TOOLBOX_GATE_SPAN=2*e.GATE_RADIUS+e.TOOLBOX_GATE_SPACING,e.TOOLBOX_GROUP_SPAN=2*e.TOOLBOX_GATE_SPAN+e.TOOLBOX_GROUP_SPACING,e.TOOLBOX_MARGIN_X=35,e.TOOLBOX_MARGIN_Y=18,e.MINIMUM_CANVAS_HEIGHT=400,e.SUPPRESSED_GLSL_WARNING_PATTERNS=[],e.DEFAULT_FILL_COLOR="white",e.DEFAULT_STROKE_COLOR="black",e.DEFAULT_TEXT_COLOR="black",e.DEFAULT_FONT_SIZE=12,e.DEFAULT_FONT_FAMILY="sans-serif",e.DEFAULT_STROKE_THICKNESS=1,e.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS=!1,e.SEMI_STABLE_RANDOM_VALUE_LIFETIME_MILLIS=300,{get Config(){return e}}}),$traceurRuntime.registerModule("src/draw/CachablePainting.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/draw/CachablePainting.js")).Painter,t=new(0,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/RestartableRng.js","src/draw/CachablePainting.js")).RestartableRng),r=function(){return $traceurRuntime.createClass(function(e,t){this.sizeFunc=e,this._drawingFunc=t,this._cachedCanvases=new Map},{paint:function(r,n,i){var a=arguments[3];if(!this._cachedCanvases.has(a)){var o=document.createElement("canvas"),u=this.sizeFunc(a),s=u.width,c=u.height;o.width=s,o.height=c,this._drawingFunc(new e(o,t.restarted()),a),this._cachedCanvases.set(a,o)}i.ctx.drawImage(this._cachedCanvases.get(a),r,n)}},{})}();return{get CachablePainting(){return r}}}),$traceurRuntime.registerModule("src/draw/GateDrawParams.js",[],function(){"use strict";var e=function(){return $traceurRuntime.createClass(function(e,t,r,n,i,a,o,u,s,c,l){this.painter=e,this.isInToolbox=t,this.isHighlighted=r,this.isResizeShowing=n,this.isResizeHighlighted=i,this.rect=a,this.gate=o,this.stats=u,this.positionInCircuit=s,this.focusPoints=c,this.customStats=l},{getGateContext:function(e){if(void 0!==this.positionInCircuit)return this.stats.circuitDefinition.colCustomContextFromGates(this.positionInCircuit.col,0).get(e)}},{})}();return{get GateDrawParams(){return e}}}),$traceurRuntime.registerModule("src/draw/GatePainting.js",[],function(){"use strict";function e(e,t,r){for(var n=t.split("\n"),i=1;i<n.length;i++)e.print(n[i],r.x+r.w/2,r.y+r.h/2+9*i,"center","hanging","black",c,r.w,16);return{symbol:n[0],offsetY:n.length>1?-5:0}}function t(e,t){return e.rect.center().y+(t-e.gate.height/2+.5)*n.WIRE_SPACING}function r(e){for(var r=0;r<e.gate.height;r++){var i=t(e,r),o=new a(e.rect.x,i),u=new a(e.rect.x+n.GATE_RADIUS,i),s=new a(e.rect.right(),i),c=new a(e.positionInCircuit.col,e.positionInCircuit.row+r),l=e.stats.circuitDefinition.locIsMeasured(c),d=e.stats.circuitDefinition.locIsMeasured(c.offsetBy(1,0)),m=!0,f=!1,h=void 0;try{for(var g=void 0,p=(l?[-1,1]:[0])[Symbol.iterator]();!(m=(g=p.next()).done);m=!0){var v=g.value;e.painter.strokeLine(o.offsetBy(0,v),u.offsetBy(1,v),"white")}}catch(e){f=!0,h=e}finally{try{m||null==p.return||p.return()}finally{if(f)throw h}}var y=!0,b=!1,R=void 0;try{for(var w=void 0,M=(d?[-1,1]:[0])[Symbol.iterator]();!(y=(w=M.next()).done);y=!0){var _=w.value;e.painter.strokeLine(u.offsetBy(-1,_),s.offsetBy(0,_),"white")}}catch(e){b=!0,R=e}finally{try{y||null==M.return||M.return()}finally{if(b)throw R}}}}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/draw/GatePainting.js")).Config,i=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GateDrawParams.js","src/draw/GatePainting.js")).GateDrawParams,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/draw/GatePainting.js")).MathPainter),a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/draw/GatePainting.js")).Point,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/draw/GatePainting.js")).Rect,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/draw/GatePainting.js")).Util,s=function(){return $traceurRuntime.createClass(function(){},{},{})}(),c="16px sans-serif";s.paintOutline=function(e){if(e.isInToolbox){var t=e.rect.shiftedBy(.5,.5);e.painter.strokeLine(t.topRight(),t.bottomRight()),e.painter.strokeLine(t.bottomLeft(),t.bottomRight())}e.painter.strokeRect(e.rect,"black")},s.paintBackground=function(e){var t=void 0!==arguments[1]?arguments[1]:n.GATE_FILL_COLOR,r=void 0!==arguments[2]?arguments[2]:n.GATE_FILL_COLOR,i=e.isInToolbox?t:r;e.isHighlighted&&(i=n.HIGHLIGHTED_GATE_FILL_COLOR),e.painter.fillRect(e.rect,i)},s.LABEL_DRAWER=function(e){if(void 0===e.positionInCircuit||e.isHighlighted)s.DEFAULT_DRAWER(e);else{var t=Math.max(0,e.rect.h-2*n.GATE_RADIUS)/2;e.painter.fillRect(e.rect.skipTop(t).skipBottom(t),n.GATE_FILL_COLOR),s.paintGateSymbol(e)}},s.MAKE_HIGHLIGHTED_DRAWER=function(){var e=void 0!==arguments[0]?arguments[0]:n.GATE_FILL_COLOR,t=void 0!==arguments[1]?arguments[1]:n.GATE_FILL_COLOR;return function(r){s.paintBackground(r,e,t),s.paintOutline(r),s.paintResizeTab(r),s.paintGateSymbol(r)}},s.DEFAULT_DRAWER=s.MAKE_HIGHLIGHTED_DRAWER(),s.rectForResizeTab=function(e){var t=Math.min(n.GATE_RADIUS,e.h/4);return new o(e.x,e.bottom()-t,e.w,2*n.GATE_RADIUS)},s.paintResizeTab=function(e){if(e.isResizeShowing&&e.gate.canChangeInSize()){var t=n.GATE_RADIUS,r=s.rectForResizeTab(e.rect).skipLeft(2).skipRight(2),i=r.center(),a=i.x,o=i.y,u=e.isResizeHighlighted?n.HIGHLIGHTED_GATE_FILL_COLOR:n.GATE_FILL_COLOR,c=e.isResizeHighlighted?"#222":"gray";e.painter.ctx.save(),e.painter.ctx.globalAlpha*=e.isResizeHighlighted?1:.7,e.painter.fillRect(r,u),e.painter.strokeRect(r,"gray"),e.painter.ctx.restore(),e.painter.print("resize",a,o,"center","middle",c,"monospace",r.w-4,r.h-4),e.painter.trace(function(r){var n=[e.gate.canIncreaseInSize()?1:-1,e.gate.canDecreaseInSize()?-1:1],i=[1,-1],u=!0,s=!1,c=void 0;try{for(var l=void 0,d=[-1,1][Symbol.iterator]();!(u=(l=d.next()).done);u=!0)for(var m=l.value,f=0;f<2;f++){var h=o+t*i[f]*5/8,g=h+t*n[f]/8,p=h-t*n[f]/8;r.line(a,g,a+t*m*.3,p)}}catch(e){s=!0,c=e}finally{try{u||null==d.return||d.return()}finally{if(s)throw c}}}).thenStroke(c)}},s.paintGateSymbol=function(t){var r,n,i=arguments[1],a=t.painter,o=t.rect.paddedBy(-2);void 0===i&&(i=t.gate.symbol);var u=e(t.painter,i,o),s=u.symbol,l=u.offsetY;a.ctx.font=c;var d=s.split("^");if(2===d.length&&""!==d[0]&&""!==d[1]){var m=(r=d[Symbol.iterator](),(n=r.next()).done?void 0:n.value),f=(n=r.next()).done?void 0:n.value;m=m.split("\n")[0];var h=a.ctx.measureText(m).width,g=a.ctx.measureText(f).width,p=Math.min(o.w,h+g)/(h+g),v=o.w/2+(h-g)*p/2;a.print(m,o.x+v,o.y+o.h/2+l,"right","hanging","black",c,v,o.h),a.print(f,o.x+v,o.y+o.h/2+l,"left","alphabetic","black",c,o.w-v,o.h)}else a.print(s,o.x+o.w/2,o.y+o.h/2+l,"center","middle","black",c,o.w,o.h)},s.traceLocationIndependentOutline=function(e,t){var r,i,a=(r=[e.rect.x,e.rect.right(),e.rect.y,e.rect.bottom()][Symbol.iterator](),(i=r.next()).done?void 0:i.value),o=(i=r.next()).done?void 0:i.value,u=(i=r.next()).done?void 0:i.value,s=(i=r.next()).done?void 0:i.value,c=Math.min(e.rect.h,e.rect.w,2*n.GATE_RADIUS)/(2+Math.sqrt(2));t.polygon([a,u+c,a+c,u,o-c,u,o,u+c,o,s-c,o-c,s,a+c,s,a,s-c])},s.paintLocationIndependentFrame=function(e){var t=void 0!==arguments[1]?arguments[1]:n.GATE_FILL_COLOR,r=void 0!==arguments[2]?arguments[2]:n.GATE_FILL_COLOR;if(e.isInToolbox)return s.paintBackground(e,r,t),void s.paintOutline(e);var i=e.isHighlighted?n.HIGHLIGHTED_GATE_FILL_COLOR:t;e.painter.trace(function(t){return s.traceLocationIndependentOutline(e,t)}).thenFill(i).thenStroke("black")},s.makeLocationIndependentGateDrawer=function(e){return function(t){s.paintLocationIndependentFrame(t,e),s.paintGateSymbol(t)}},s.LOCATION_INDEPENDENT_GATE_DRAWER=s.makeLocationIndependentGateDrawer(n.GATE_FILL_COLOR),s.SECTIONED_DRAWER_MAKER=function(e,t){return function(r){if(r.isInToolbox)s.DEFAULT_DRAWER(r);else{var i=r.isHighlighted?n.HIGHLIGHTED_GATE_FILL_COLOR:n.GATE_FILL_COLOR;r.painter.fillRect(r.rect,i);for(var o=0,u=0;u<e.length;u++){var c=void 0;if(u<e.length-1){c=o+t[u];var l=r.rect.y+r.rect.h*c;r.painter.strokeLine(new a(r.rect.x,l),new a(r.rect.right(),l),"#BBB")}else c=1;r.painter.print(e[u],r.rect.x+r.rect.w/2,r.rect.y+r.rect.h*(o+c)/2,"center","middle","black","16px sans-serif",r.rect.w-2,r.rect.h*(c-o)),o=c}r.painter.strokeRect(r.rect),s.paintResizeTab(r)}}};var l=s.MAKE_HIGHLIGHTED_DRAWER(n.DISPLAY_GATE_IN_TOOLBOX_FILL_COLOR);return s.makeDisplayDrawer=function(e){return function(t){void 0!==t.positionInCircuit?(s.paintResizeTab(t),e(t),t.isHighlighted&&t.painter.strokeRect(t.rect,"black",1.5),t.painter.ctx.save(),t.painter.ctx.globalAlpha*=.25,s.paintResizeTab(t),t.painter.ctx.restore()):l(t)}},s.MATRIX_DRAWER=function(e){var t=e.gate.knownMatrixAt(e.stats.time);void 0!==t?(e.painter.fillRect(e.rect,e.isHighlighted?n.HIGHLIGHTED_GATE_FILL_COLOR:n.GATE_FILL_COLOR),i.paintMatrix(e.painter,t,e.rect,n.OPERATION_FORE_COLOR,"black",void 0,n.OPERATION_BACK_COLOR,void 0,"transparent"),e.isHighlighted&&(e.painter.ctx.save(),e.painter.ctx.globalAlpha*=.9,e.painter.fillRect(e.rect,n.HIGHLIGHTED_GATE_FILL_COLOR),e.painter.ctx.restore()),s.paintOutline(e)):s.DEFAULT_DRAWER(e)},s.makeCycleDrawer=function(){var e=void 0!==arguments[0]?arguments[0]:1,t=void 0!==arguments[1]?arguments[1]:1,r=void 0!==arguments[2]?arguments[2]:1,i=void 0!==arguments[3]?arguments[3]:0;return function(a){if(s.MAKE_HIGHLIGHTED_DRAWER(n.TIME_DEPENDENT_HIGHLIGHT_COLOR)(a),!a.isInToolbox||a.isHighlighted){var o=2*Math.PI,c=u.properMod(-a.stats.time*o*r,o),l=a.rect.center(),d=.4*a.rect.w;a.painter.ctx.save(),a.painter.ctx.translate(l.x,l.y),a.painter.ctx.scale(-e,-t),a.painter.ctx.rotate(i),a.painter.ctx.strokeStyle="black",a.painter.ctx.fillStyle="yellow",a.painter.ctx.globalAlpha*=.4,a.painter.ctx.beginPath(),a.painter.ctx.moveTo(0,0),a.painter.ctx.lineTo(0,d),a.painter.ctx.arc(0,0,d,o/4,o/4+c,!0),a.painter.ctx.lineTo(0,0),a.painter.ctx.closePath(),a.painter.ctx.stroke(),a.painter.ctx.fill(),a.painter.ctx.restore()}}},s.MATRIX_SYMBOL_DRAWER_EXCEPT_IN_TOOLBOX=function(e){e.isInToolbox?s.DEFAULT_DRAWER(e):s.MATRIX_DRAWER(e)},s.gateButtonRect=function(e){return e.bottomHalf().skipTop(6).paddedBy(-7)},s.paintGateButton=function(e){if(e.isHighlighted&&!e.isInToolbox){var t=s.gateButtonRect(e.rect),r=!e.focusPoints.every(function(e){return!t.containsPoint(e)});e.painter.fillRect(t,r?"red":"orange"),e.painter.print("change",t.center().x,t.center().y,"center","middle","black","12px sans-serif",t.w,t.h),e.painter.strokeRect(t,"black")}},s.PERMUTATION_DRAWER=function(e){var n,i;if(void 0!==e.positionInCircuit){e.isHighlighted||e.isResizeHighlighted||e.stats.circuitDefinition.colHasControls(e.positionInCircuit.col)?(s.paintBackground(e,"#F3F3F3","#F3F3F3"),s.paintOutline(e),s.paintResizeTab(e)):r(e);var o=e.rect.x,u=e.rect.right();e.painter.ctx.strokeStyle="black";for(var c=0;c<e.gate.height;c++){var l=e.gate.knownBitPermutationFunc(c),d=new a(e.positionInCircuit.col,e.positionInCircuit.row+c),m=e.stats.circuitDefinition.locIsMeasured(d),f=t(e,c),h=t(e,l);e.painter.ctx.beginPath();var g=!0,p=!1,v=void 0;try{for(var y=void 0,b=(m?[[l>c?1:-1,-1],[0,1]]:[[0,0]])[Symbol.iterator]();!(g=(y=b.next()).done);g=!0){var R=(n=y.value[Symbol.iterator](),(i=n.next()).done?void 0:i.value),w=(i=n.next()).done?void 0:i.value;e.painter.ctx.moveTo(Math.min(o,o+R),f+w),e.painter.ctx.lineTo(o+R,f+w),e.painter.ctx.lineTo(u+R,h+w),e.painter.ctx.lineTo(Math.max(u,u+R),h+w)}}catch(e){p=!0,v=e}finally{try{g||null==b.return||b.return()}finally{if(p)throw v}}e.painter.ctx.stroke()}}else s.DEFAULT_DRAWER(e)},{get GatePainting(){return s}}}),$traceurRuntime.registerModule("src/draw/MathPainter.js",[],function(){"use strict";$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/draw/MathPainter.js")).Painter;var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/draw/MathPainter.js")).Format,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/draw/MathPainter.js")).Point,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/draw/MathPainter.js")).Rect,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/draw/MathPainter.js")),i=n.seq,a=n.Seq,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/draw/MathPainter.js")).Util,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/draw/MathPainter.js")).Config,s=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/draw/MathPainter.js")).Complex,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/draw/MathPainter.js")).Matrix),c=function(){function n(){}return $traceurRuntime.createClass(n,{},{describeProbability:function(e,t){var r=100*e,n=Math.pow(10,-t);return r>100-n/2?"On":r<n/2?"Off":Math.min(Math.max(r,n),100-n).toFixed(t)+"%"},paintProbabilityBox:function(e,t,r){var a=void 0!==arguments[3]?arguments[3]:[],o=void 0!==arguments[4]?arguments[4]:u.DISPLAY_GATE_BACK_COLOR,s=void 0!==arguments[5]?arguments[5]:u.DISPLAY_GATE_FORE_COLOR;e.fillRect(r,o);var c=r.center();isNaN(t)?(e.fillPolygon([r.bottomLeft(),r.topLeft(),r.topRight()],s),e.print("NaN",c.x,c.y,"center","middle","red","9pt sans-serif",r.w,r.h)):(e.fillRect(r.takeBottomProportion(t),s),e.print(n.describeProbability(t,1),c.x,c.y,"center","middle","black","9pt sans-serif",r.w,r.h)),e.strokeRect(r,"lightgray"),i(a).any(function(e){return r.containsPoint(e)})&&(e.strokeRect(r,"orange",2),n.paintDeferredValueTooltip(e,r.right(),r.y,"Chance of being ON if measured",(100*t).toFixed(5)+"%"))},paintMatrixTooltip:function(e,t,i,a,o,u){var s=void 0!==arguments[6]?arguments[6]:function(){},c=t.width(),l=t.height(),d=i,m=d.x,f=d.y,h=Math.min(i.w/c,i.h/l),g=!0,p=!1,v=void 0;try{for(var y=void 0,b=a[Symbol.iterator]();!(g=(y=b.next()).done);g=!0){var R=y.value,w=Math.floor((R.x-m)/h),M=Math.floor((R.y-f)/h);if(w>=0&&w<t.width()&&M>=0&&M<t.height()){e.strokeRect(new r(m+h*w,f+h*M,h,h),"orange",2);var _=t.cell(w,M);n.paintDeferredValueTooltip(e,m+h*w+h,f+h*M,o(w,M),u(w,M,_),s(w,M,_))}}}catch(e){p=!0,v=e}finally{try{g||null==b.return||b.return()}finally{if(p)throw v}}},_traceAmplitudeProbabilitySquare:function(e,t,r,n,i,a){var o=t*t+r*r;o>.001&&e.polygon([n,i+a*(1-o),n+a,i+a*(1-o),n+a,i+a,n,i+a])},_traceProbabilitySquare:function(e,t,r,n,i,a){var o=t;a*o>.1&&e.polygon([n,i+a*(1-o),n+a,i+a*(1-o),n+a,i+a,n,i+a])},_traceAmplitudeProbabilityCircle:function(e,t,r,n,i,a){var o=Math.sqrt(t*t+r*r);a*o>.5&&e.circle(n+a/2,i+a/2,o*a/2)},_traceAmplitudeLogarithmCircle:function(e,t,r,n,i,a){var o=1+Math.log(t*t+r*r)/15;o>0&&e.circle(n+a/2,i+a/2,o*a/2)},_traceAmplitudePhaseDirection:function(e,t,r,n,i,a){var o=Math.sqrt(t*t+r*r),u=1+Math.log(o)/10,s=Math.max(1,u/o)*Math.max(a/2,5);if(!(s<.1)){var c=n+a/2,l=i+a/2;e.line(c,l,c+t*s,l-r*s)}},paintMatrix:function(e,t,r,i,a,o){var s=void 0!==arguments[6]?arguments[6]:u.DISPLAY_GATE_BACK_COLOR,c=arguments[7],l=void 0!==arguments[8]?arguments[8]:"#AAA",d=t.width(),m=t.height(),f=t.rawBuffer(),h=Math.min(r.w/d,r.h/m),g=r=r.withW(h*d).withH(h*m),p=g.x,v=g.y,y=t.hasNaN();c=c||a,e.fillRect(r,s);var b=function(t){return e.trace(function(e){for(var r=0;r<m;r++)for(var n=0;n<d;n++){var i=2*(r*d+n);t(e,f[i],f[i+1],p+h*n,v+h*r,h)}})};y||(void 0!==o&&b(n._traceAmplitudeProbabilitySquare).thenFill(o).thenStroke("lightgray",.5),void 0!==i&&(b(n._traceAmplitudeProbabilityCircle).thenFill(i).thenStroke(a,.5),b(n._traceAmplitudeLogarithmCircle).thenStroke(l,.5))),e.trace(function(e){return e.grid(p,v,r.w,r.h,d,m)}).thenStroke("lightgray"),y||void 0!==l&&b(n._traceAmplitudePhaseDirection).thenStroke(c),y&&e.print("NaN",r.x+r.w/2,r.y+r.h/2,"center","middle","red","16px sans-serif",r.w,r.h)},paintDeferredValueTooltip:function(e,t,n,i,a){var o=arguments[5],s=void 0!==arguments[6]?arguments[6]:u.DISPLAY_GATE_BACK_COLOR,c="bold 12px monospace";e.defer(function(){e.ctx.font="12px sans-serif";var u=e.ctx.measureText(i).width;e.ctx.font=c;var l=e.ctx.measureText(a).width,d=void 0===o?0:e.ctx.measureText(o).width,m=40+(void 0===o?0:20),f=Math.max(Math.max(u,l),d),h=new r(t,n-m,f,m).snapInside(new r(0,0,e.ctx.canvas.clientWidth,e.ctx.canvas.clientHeight)),g=function(t,n){var i=new r(h.x,h.bottom()-n,t,n).paddedBy(4);e.trace(function(e){return e.rect(i.x,i.y,i.w,i.h)}).thenFill(s).thenStroke("black")},p=function(t,r){e.print(i,h.x,h.bottom()-r,"left","bottom","black","12px sans-serif",h.w,20,function(e,n){return g(Math.max(t,e),r+n)})},v=function(t,r){e.print(a,h.x,h.bottom()-r,"left","bottom","black",c,h.w,20,function(e,n){return p(Math.max(t,e),r+n)})};void 0===o?v(0,0):e.print(o,h.x,h.bottom(),"left","bottom","black",c,h.w,20,v)})},coordinateSystem:function(e){return{dx:new t(e/3,-e/3),dy:new t(e,0),dz:new t(0,e)}},paintBlochSphereRotation:function(e,r,o){var c,l=void 0!==arguments[3]?arguments[3]:u.DISPLAY_GATE_BACK_COLOR,d=void 0!==arguments[4]?arguments[4]:u.DISPLAY_GATE_FORE_COLOR,m=o.center(),f=Math.min(o.w,o.h)/2,h=n.coordinateSystem(f),g=h.dx,p=h.dy,v=h.dz,y=s.fromRows([[-g.x,-g.y],[p.x,p.y],[-v.x,-v.y]]).adjoint(),b=function(e){var r=y.times(e);return new t(r.cell(0,0).real,r.cell(0,1).real)},R=a.range(3).map(function(e){return s.generate(1,3,function(t,r){return t===e?1:0})}).toArray();e.fillCircle(m,f,l),e.trace(function(e){e.circle(m.x,m.y,f),e.ellipse(m.x,m.y,f,f/3),e.ellipse(m.x,m.y,f/3,f);var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=R[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value,u=b(o);e.line(m.x-u.x,m.y-u.y,m.x+u.x,m.y+u.y)}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}).thenStroke("#BBB");var w=r.qubitOperationToAngleAxisRotation(),M=w.angle,_=w.axis,x=(c=s).col.apply(c,$traceurRuntime.spread(_)),S=b(x),T=[s.col(_[0],_[1],0),x,s.col(0,0,_[2])].map(b);e.strokePolygon(i(T).reverse().concat(T.map(function(e){return e.times(-1)})).map(function(e){return m.plus(e)}).toArray(),"#666"),e.strokeLine(m.plus(S),m.plus(S.times(-1)),"black",2);var A=function(e){return Math.sqrt(e.adjoint().times(e).cell(0,0).real)},C=i(R).mapWithIndex(function(e,t){return e.times([-3,-2,1][t])}).map(function(e){return x.cross3(e)}).maxBy(A),$=x.cross3(C);C=C.times(.15/A(C)),$=$.times(.15/A($));var j=b(C),E=b($);n._paintBlochSphereRotation_rotationGuideArrows(e,m,M,S,j,E,d)},_paintBlochSphereRotation_rotationGuideArrows:function(e,t,r,n,i,o,u){var s=a.range(Math.floor(32*Math.abs(r))).map(function(e){var t=r<0?Math.PI-e/32:e/32;return i.times(Math.cos(t)).plus(o.times(Math.sin(t)))}).toArray();if(!(s.length<=1)){var c=!0,l=!1,d=void 0;try{for(var m=void 0,f=[-.55,0,.55][Symbol.iterator]();!(c=(m=f.next()).done);c=!0)!function(){var r=m.value,i=t.plus(n.times(r)),a=s.map(function(e){return i.plus(e)}),o=a[a.length-1],c=o.plus(a[a.length-2].times(-1)),l=[n.times(.15),c.times(30),n.times(-.15)].map(function(e){return o.plus(e)}),d=[].concat.apply([],l.map(function(e){return[e.x,e.y]}));e.strokePath(a,"#444"),e.trace(function(e){return e.polygon(d)}).thenFill(u).thenStroke("#444")}()}catch(e){l=!0,d=e}finally{try{c||null==f.return||f.return()}finally{if(l)throw d}}}},paintDensityMatrix:function(t,r,i){var a=void 0!==arguments[3]?arguments[3]:[],s=void 0!==arguments[4]?arguments[4]:u.DISPLAY_GATE_BACK_COLOR,c=void 0!==arguments[5]?arguments[5]:u.DISPLAY_GATE_FORE_COLOR,l=r.width(),d=r.height(),m=r.rawBuffer(),f=Math.min(i.w/l,i.h/d),h=i.x,g=i.y,p=r.hasNaN(),v=function(e){return t.trace(function(t){for(var r=0;r<d;r++)for(var n=0;n<l;n++){var i=2*(r*l+n);e(t,m[i],m[i+1],h+f*n,g+f*r,f)}})};t.fillRect(i,s),p||(function(e){return t.trace(function(t){for(var r=0;r<d;r++){var n=r*(l+1)*2;e(t,m[n],m[n+1],h+f*r,g+f*r,f)}})}(n._traceProbabilitySquare).thenFill(c).thenStroke("#040",.5),v(n._traceAmplitudeProbabilityCircle).thenFill(c).thenStroke("#040",.5),v(n._traceAmplitudeLogarithmCircle).thenStroke("#BBB",.5),v(n._traceAmplitudePhaseDirection).thenStroke("black")),i.w/l>2?t.trace(function(e){return e.grid(h,g,i.w,i.h,l,d)}).thenStroke("lightgray",Math.min(1,2/Math.log(l))):(t.ctx.save(),t.ctx.globalAlpha*=.2,t.fillRect(i,"lightgray"),t.ctx.restore()),p&&t.print("NaN",i.x+i.w/2,i.y+i.h/2,"center","middle","red","16px sans-serif",i.w,i.h);var y=Math.round(Math.log2(d));n.paintMatrixTooltip(t,r,i,a,function(e,t){return e===t?"Probability of |"+o.bin(e,y)+"⟩":"Coupling of |"+o.bin(e,y)+"⟩ to ⟨"+o.bin(t,y)+"|"},function(t,n,i){return t===n?(100*r.cell(t,n).real).toFixed(4)+"%":r.cell(t,n).toString(new e(!1,0,6,", "))})}})}();return{get MathPainter(){return c}}}),$traceurRuntime.registerModule("src/draw/Painter.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/draw/Painter.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/draw/Painter.js")).Point,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/draw/Painter.js")).Rect,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/RestartableRng.js","src/draw/Painter.js")).RestartableRng,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/draw/Painter.js")),a=i.seq,o=i.Seq,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/draw/Painter.js")).Util,s=function(){return $traceurRuntime.createClass(function(e){var t=void 0!==arguments[1]?arguments[1]:new n;this.canvas=e,this.ctx=e.getContext("2d"),this._deferredPaintActions=[],this._traceAction=new l(this.ctx),this._tracer=new c(this.ctx),this.desiredCursorStyle=void 0,this.touchBlockers=[],this.rng=t},{noteTouchBlocker:function(e){this.touchBlockers.push(e)},setDesiredCursor:function(e){this.desiredCursorStyle=e},defer:function(e){this._deferredPaintActions.push(e)},paintDeferred:function(){var e=!0,t=!1,r=void 0;try{for(var n=void 0,i=this._deferredPaintActions[Symbol.iterator]();!(e=(n=i.next()).done);e=!0)(0,n.value)()}catch(e){t=!0,r=e}finally{try{e||null==i.return||i.return()}finally{if(t)throw r}}this._deferredPaintActions=[]},paintableArea:function(){return new r(0,0,this.canvas.width,this.canvas.height)},clear:function(){var t=void 0!==arguments[0]?arguments[0]:e.DEFAULT_FILL_COLOR;this.ctx.fillStyle=t,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height)},strokeLine:function(t,r){var n=void 0!==arguments[2]?arguments[2]:e.DEFAULT_STROKE_COLOR,i=void 0!==arguments[3]?arguments[3]:1;this.ctx.beginPath(),this.ctx.moveTo(t.x,t.y),this.ctx.lineTo(r.x,r.y),this.ctx.strokeStyle=n,this.ctx.lineWidth=i,this.ctx.stroke()},strokeRect:function(e){var t=void 0!==arguments[1]?arguments[1]:"black",r=void 0!==arguments[2]?arguments[2]:1;this.ctx.strokeStyle=t,this.ctx.lineWidth=r,this.ctx.strokeRect(e.x,e.y,e.w,e.h)},fillRect:function(t){var r=void 0!==arguments[1]?arguments[1]:e.DEFAULT_FILL_COLOR;this.ctx.fillStyle=r,this.ctx.fillRect(t.x,t.y,t.w,t.h)},strokeCircle:function(t,r){var n=void 0!==arguments[2]?arguments[2]:e.DEFAULT_STROKE_COLOR,i=void 0!==arguments[3]?arguments[3]:e.DEFAULT_STROKE_THICKNESS;this.ctx.beginPath(),this.ctx.strokeStyle=n,this.ctx.lineWidth=i,this.ctx.arc(t.x,t.y,Math.max(r-.5,0),0,2*Math.PI),this.ctx.stroke()},trace:function(e){return this.ctx.beginPath(),e(this._tracer),this._traceAction},fillCircle:function(t,r){var n=void 0!==arguments[2]?arguments[2]:e.DEFAULT_FILL_COLOR;this.ctx.beginPath(),this.ctx.arc(t.x,t.y,Math.max(r-.5,0),0,2*Math.PI),this.ctx.fillStyle=n,this.ctx.fill()},print:function(e,t,r,n,i,a,o,u,s){var c=arguments[9],l=void 0!==arguments[10]&&arguments[10];this.ctx.font=o;var d=this.ctx.measureText(e).width,m=2.5*this.ctx.measureText("0").width,f=Math.min(Math.min(u/d,s/m),1);void 0!==c&&c(d*f,m*f),this.ctx.save(),this.ctx.textAlign=n,this.ctx.textBaseline=i,this.ctx.font=o,this.ctx.fillStyle=a,this.ctx.translate(t,r),this.ctx.scale(f,f),l&&this.ctx.strokeText(e,0,0),this.ctx.fillText(e,0,0),this.ctx.restore()},printParagraph:function(n,i){for(var s,c,l,d,m=void 0!==arguments[2]?arguments[2]:new t(0,0),f=void 0!==arguments[3]?arguments[3]:e.DEFAULT_TEXT_COLOR,h=void 0!==arguments[4]?arguments[4]:e.DEFAULT_FONT_SIZE,g=void 0!==arguments[5]?arguments[5]:e.DEFAULT_FONT_FAMILY,p=this,v=function(e){var t=e.fontBoundingBoxAscent;return void 0===t?.75*s:t},y=function(e){var t=e.fontBoundingBoxDescent;return void 0===t?.25*s:t},b=a(n.split("\n")),R=0;s=h-R,this.ctx.font=s+"px "+g,c=b.flatMap(function(e){return u.breakLine(e,i.w,function(e){return p.ctx.measureText(e).width})}).toArray(),l=c.map(function(e){return p.ctx.measureText(e)}),!((d=a(l.map(function(e){return v(e)+y(e)})).sum())<=i.h||s<=4);R++);var w=function(e,t,r,n){return e+(t-r)*n},M=function(e){return w(i.x,i.w,e,m.x)},_=function(e){return w(i.y,i.h,e,m.y)}(d);this.ctx.fillStyle=f;for(var x=0,S=0;S<c.length;S++)x+=v(l[S]),this.ctx.fillText(c[S],M(l[S].width),_+x),x+=y(l[S]);var T=new o(l).map(function(e){return e.width}).max(0);return new r(M(T),_,T,d)},printLine:function(t,n){for(var i,a,o=void 0!==arguments[2]?arguments[2]:0,u=void 0!==arguments[3]?arguments[3]:e.DEFAULT_TEXT_COLOR,s=void 0!==arguments[4]?arguments[4]:e.DEFAULT_FONT_SIZE,c=void 0!==arguments[5]?arguments[5]:e.DEFAULT_FONT_FAMILY,l=arguments[6],d=function(e){var t=e.fontBoundingBoxAscent;return void 0===t?.75*i:t},m=function(e){var t=e.fontBoundingBoxDescent;return void 0===t?.25*i:t},f=function(e){return d(e)+m(e)},h=0;i=s-h,this.ctx.font=i+"px "+c,!((a=this.ctx.measureText(t)).width<=n.w&&f(a)<=n.h||i<=4);h++);var g=f(a),p=void 0===l?d(a)/g:l,v=function(e,t,r,n){return e+(t-r)*n},y=v(n.x,n.w,a.width,o),b=v(n.y,n.h,g,p);return this.ctx.fillStyle=u,this.ctx.fillText(t,y,b+d(a)),new r(y,b,a.width,g)},strokePolygon:function(t){var r=void 0!==arguments[1]?arguments[1]:e.DEFAULT_STROKE_COLOR,n=void 0!==arguments[2]?arguments[2]:e.DEFAULT_STROKE_THICKNESS;if(0!==t.length){var i=t[t.length-1];this.ctx.beginPath(),this.ctx.moveTo(i.x,i.y);var a=!0,o=!1,u=void 0;try{for(var s=void 0,c=t[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value;this.ctx.lineTo(l.x,l.y)}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}this.ctx.strokeStyle=r,this.ctx.lineWidth=n,this.ctx.stroke()}},strokePath:function(t){var r=void 0!==arguments[1]?arguments[1]:e.DEFAULT_STROKE_COLOR,n=void 0!==arguments[2]?arguments[2]:e.DEFAULT_STROKE_THICKNESS;if(0!==t.length){this.ctx.beginPath(),this.ctx.moveTo(t[0].x,t[0].y);var i=!0,a=!1,o=void 0;try{for(var u=void 0,s=t.slice(1)[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value;this.ctx.lineTo(c.x,c.y)}}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}this.ctx.strokeStyle=r,this.ctx.lineWidth=n,this.ctx.stroke()}},fillPolygon:function(e,t){var r=e[e.length-1];this.ctx.beginPath(),this.ctx.moveTo(r.x,r.y);var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=e[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;this.ctx.lineTo(s.x,s.y)}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}this.ctx.fillStyle=t,this.ctx.fill()}},{})}(),c=function(){return $traceurRuntime.createClass(function(e){this.ctx=e},{line:function(e,t,r,n){this.ctx.moveTo(e,t),this.ctx.lineTo(r,n)},rect:function(e,t,r,n){this.ctx.moveTo(e,t),this.ctx.lineTo(e+r,t),this.ctx.lineTo(e+r,t+n),this.ctx.lineTo(e,t+n),this.ctx.lineTo(e,t)},circle:function(e,t,r){this.ctx.moveTo(e+r,t),this.ctx.arc(e,t,r,0,2*Math.PI,!1)},ellipse:function(e,t,r,n){this.ctx.save(),this.ctx.translate(e-r,t-n),this.ctx.scale(r,n),this.ctx.moveTo(2,1),this.ctx.arc(1,1,1,0,2*Math.PI,!1),this.ctx.restore()},grid:function(e,t,r,n,i,a){for(var o=r/i,u=n/a,s=e+i*o,c=t+a*u,l=0;l<=i;l++)this.ctx.moveTo(e+l*o,t),this.ctx.lineTo(e+l*o,c);for(var d=0;d<=a;d++)this.ctx.moveTo(e,t+d*u),this.ctx.lineTo(s,t+d*u)},polygon:function(e){if(0!==e.length){var t=e.length;this.ctx.moveTo(e[t-2],e[t-1]);for(var r=0;r<t;r+=2)this.ctx.lineTo(e[r],e[r+1])}},arrowHead:function(e,t,r,n,i){var a=n+i/2+Math.PI,o=n-i/2+Math.PI;this.polygon([e+Math.cos(n)*r,t+Math.sin(n)*r,e+Math.cos(a)*r,t+Math.sin(a)*r,e+Math.cos(o)*r,t+Math.sin(o)*r])}},{})}(),l=function(){return $traceurRuntime.createClass(function(e){this.ctx=e},{thenFill:function(e){return this.ctx.fillStyle=e,this.ctx.fill(),this},thenStroke:function(e){var t=void 0!==arguments[1]?arguments[1]:1;return this.ctx.strokeStyle=e,this.ctx.lineWidth=t,this.ctx.stroke(),this}},{})}();return{get Painter(){return s}}}),$traceurRuntime.registerModule("src/draw/WidgetPainter.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/draw/WidgetPainter.js")).Complex,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/draw/WidgetPainter.js")).Config,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/draw/WidgetPainter.js")).Format,n=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/draw/WidgetPainter.js")).Gate,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/draw/WidgetPainter.js")).MathPainter),i=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/draw/WidgetPainter.js")).Matrix,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/draw/WidgetPainter.js")).Painter,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/draw/WidgetPainter.js")).Point),a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/draw/WidgetPainter.js")).Rect,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/draw/WidgetPainter.js")).Seq,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedCircuit.js","src/draw/WidgetPainter.js")).drawCircuitTooltip,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/draw/WidgetPainter.js")).Util,c=function(){function c(){}return $traceurRuntime.createClass(c,{},{describeGateTransformations:function(e,t){var n=e.height(),i=Math.round(Math.log2(n));return o.range(n).map(function(a){var u=c.describeKet(i,a,1,r.SIMPLIFIED),s=e.getColumn(a);if(s.every(function(e){return e.isEqualTo(0)}))return"discards "+u;if(o.range(n).every(function(e){return s[e].isEqualTo(e===a?1:0)})){if(t!==r.CONSISTENT)return"doesn't affect "+u}else if(o.range(n).every(function(e){return e===a||s[e].isEqualTo(0)}))return"phases "+u+" by "+s[a].toString(t);return"transforms "+u+" into "+new o(s).mapWithIndex(function(e,r){return c.describeKet(i,r,e,t)}).filter(function(e){return""!==e}).join(" + ").split(" + -").join(" - ").split(" + +").join(" + ")}).toArray()},_paintGateTooltip_matrix:function(e,o,u,s,l,d,m,f){if(void 0!==u){m(new a(0,f(),1,0),2*s),m(e.printParagraph("As matrix:",new a(s,f(),d,18),new i(0,0),"black",12),0);var h=new a(s,f(),l,l),g=new a(0,h.y,d-s,l).skipLeft(h.right()+s);n.paintMatrix(e,u,h,t.OPERATION_FORE_COLOR,"black",void 0,t.OPERATION_BACK_COLOR,void 0,"transparent"),m(h);var p=u.height();if(p<=4)for(var v=o.stableDuration()<.2?r.CONSISTENT:r.SIMPLIFIED,y=c.describeGateTransformations(u,v),b=g.h/p,R=0;R<p;R++)m(e.printParagraph(y[R],g.skipTop(R*b).takeTop(b),new i(0,.5),"black",12))}},_paintGateTooltip_rotation:function(e,u,s,l,d,m,f,h){if(void 0!==s&&2===s.width()&&s.isUnitary(.001)){f(new a(0,h(),1,0),2*l),f(e.printParagraph("As rotation:",new a(l,h(),m,18),new i(0,0),"black",12),0);var g=s.qubitOperationToAngleAxisRotation(),p=g.angle,v=g.axis,y=g.phase,b=new a(l,h(),d,d);n.paintBlochSphereRotation(e,s,b,t.OPERATION_BACK_COLOR,t.OPERATION_FORE_COLOR),f(b);var R=u.stableDuration()<.2?r.CONSISTENT:r.SIMPLIFIED,w=new o(["rotates: "+R.formatFloat(180*p/Math.PI)+"°","around: "+c.describeAxis(v,R),"","hidden phase: exp("+R.formatFloat(180*y/Math.PI)+"°i)",""]).join("\n");f(e.printParagraph(w,new a(0,b.y,m-l,d).skipLeft(b.right()+l),new i(0,.5),"black",12))}},_paintGateTooltip_circuit:function(e,t,r,n,o,s,c,l){if(void 0!==t){var d=t.gateWeight();s(new a(0,c(),1,0),2*r),s(e.printParagraph("As circuit (gate weight = "+d+"):",new a(r,c(),o,18),new i(0,0),"black",12),0);var m=new a(r,c(),o,n),f=u(e,t,m,!0,l),h=f.maxW,g=f.maxH;s(m.withW(h).withH(g))}},paintGateTooltipHelper:function(e,t,r,n){var o,u,s,l,d=(o=[4,65][Symbol.iterator](),(u=o.next()).done?void 0:u.value),m=(u=o.next()).done?void 0:u.value,f=(s=[0,d][Symbol.iterator](),(l=s.next()).done?void 0:l.value),h=(l=s.next()).done?void 0:l.value,g=function(e){var t=void 0!==arguments[1]?arguments[1]:d;h=Math.max(h,e.bottom()+t),f=Math.max(f,e.right()+t)};g(e.printLine(r.name,new a(d,h,t,18),0,"blue",24)),""!==r.blurb&&g(e.printParagraph(r.blurb,new a(d,h,t,50),new i(0,0),"black",14));var p=r.knownMatrixAt(n);return r.definitelyHasNoEffect()?{maxX:f,maxY:h}:(c._paintGateTooltip_matrix(e,r,p,d,m,t,g,function(){return h}),c._paintGateTooltip_rotation(e,r,p,d,m,t,g,function(){return h}),c._paintGateTooltip_circuit(e,r.knownCircuitNested,d,m,t,g,function(){return h},n),{maxX:f,maxY:h})},paintGateTooltip:function(e,t,r,n){var i=void 0===arguments[4]||arguments[4];e.ctx.save(),e.ctx.translate(t.x,t.y),t=t.withX(0).withY(0);var o=Math.min(t.w/500,t.h/300);i&&o<1&&(e.ctx.scale(o,o),t=t.withH(t.h/o).withW(t.w/o));var u=t.w,s=c.paintGateTooltipHelper(e,u,r,n),l=s.maxX,d=s.maxY,m=new a(0,0,l,d);return e.fillRect(m,"#F9FFF9"),e.strokeRect(m,"black"),c.paintGateTooltipHelper(e,u,r,n),e.ctx.restore(),{maxW:l,maxH:d}},describeKet:function(t,n,i,a){return(i=e.from(i)).isEqualTo(0)?"":(i.isEqualTo(1)?"":i.isEqualTo(-1)?"-":i.isEqualTo(e.I)?"i":i.isEqualTo(e.I.times(-1))?"-i":0!==i.real&&0!==i.imag||a===r.CONSISTENT?"("+i.toString(a)+")·":i.toString(a))+"|"+s.bin(n,t)+"⟩"},describeAxis:function(e,t){var r=new o(e).map(Math.abs).max();return new o(e).map(function(e){return e/r}).zip(["X","Y","Z"],function(e,r){return 0===e?"":1===e?r:-1===e?"-"+r:t.formatFloat(e)+"·"+r}).filter(function(e){return""!==e}).join(" + ").replace(" + -"," - ").replace(" + +"," + ")}})}();return{get WidgetPainter(){return c}}}),$traceurRuntime.registerModule("src/fallback.js",[],function(){"use strict";function e(){a=!0,window.onerror=r}function t(e,t){if(void 0===t){var r=!0,n=!1,a=void 0;try{for(var o=void 0,u=i[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var s=o.value,c=s.regex,l=s.handler;if(c.test(e))return l}}catch(e){n=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(n)throw a}}}}function r(e,t,r,n,i){try{var a=m((i instanceof Object?i.stack:void 0)||t+":"+r+":"+n),o=["URL",document.location,"","BROWSER",window.navigator.userAgent,window.navigator.appName,window.navigator.appVersion,"","ERROR OBJECT",i instanceof Object&&void 0!==i.toString?i.toString():String(i),"","ERROR LOCATION",m(a)].join("\n");c("An error happened. :(",e,o,"(Unexpected) "+e+" @ "+a.substr(0,200)+"[...]"),h(["An error is happening. :(","",e,"","Scroll down for more information"].join("\n"))}catch(e){console.error("Caused an exception when handling unexpected error.",e)}return!1}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Describe.js","src/fallback.js")).describe,i=[],a=!1,o=function(e,t,r,n){document.getElementById("error-happened-div").innerText=e,document.getElementById("error-message-div").innerText=t,document.getElementById("error-description-div").innerText=r,document.getElementById("error-mailto-anchor").innerText="Email the issue to [email protected]",document.getElementById("error-mailto-anchor").href=["mailto:[email protected]?subject=",encodeURIComponent("Quirk had an error: "+t),"&body=",encodeURIComponent("\n\n\n"+r)].join(""),document.getElementById("error-github-anchor").href=["https://github.com/Strilanc/Quirk/issues/new?title=",encodeURIComponent("Encountered error: "+t),"&body=",encodeURIComponent("\n\n\n"+r)].join(""),document.getElementById("error-image-pre").src=l(),setTimeout(function(){document.getElementById("error-image-post").src=l()},0),void 0===n?(document.getElementById("error-report-div").style.display="block",document.getElementById("error-known-div").style.display="none"):(document.getElementById("error-report-div").style.display="none",document.getElementById("error-known-div").style.display="block",document.getElementById("error-known-issue-anchor").href=n)},u=[],s=[],c=function(e,r,n,i){var a=arguments[4],c=document.getElementById("error-div").style;if(c.opacity<.7&&(u=[],s=[]),c.backgroundColor="#FFA",c.opacity=1,c.display="block",-1===u.indexOf(n)){u.push(n),s.length>0&&(n+="\n\nCOVERED\n"+s.join("\n-------------\n")),-1===s.indexOf(i)&&s.push(i);var l=t(r,a);void 0===l?o(e,r,n,a):l()}},l=function(){var e=document.getElementById("drawCanvas");return void 0===e?"#":e.toDataURL("image/png")},d=function(e,t,r){if(!a)throw r;console.error("Recovered from unexpected error",{recovery:e,context:t,error:r});var i=r.stack||"unknown",o=[e,"","URL",document.location,"","BROWSER",window.navigator.userAgent,window.navigator.appName,window.navigator.appVersion,"","RECOVERY DETAILS",n(t),"","ERROR OBJECT",n(r),"","ERROR LOCATION",m(i)].join("\n");c("Recovered from an error. :(",e+" ("+(r.message||"")+")",o,"(Recovered) "+e+" @ "+i.substr(0,200)+"[...]")},m=function(e){return e.replace(/http.+?\/src\.min\.js/g,"src.min.js")},f=function(e,t,r){var n=function(){return c("A known problem is happening. :(",e,"",e,t)},a=!0,o=!1,u=void 0;try{for(var s=void 0,l=r[Symbol.iterator]();!(a=(s=l.next()).done);a=!0){var d=s.value;i.push({regex:d,handler:n})}}catch(e){o=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(o)throw u}}n()},h=function(e){var t=document.getElementById("drawCanvas");if(void 0!==t){var r=t.getContext("2d");r.font="12px monospace";var n=e.split("\n"),i=0,a=!0,o=!1,u=void 0;try{for(var s=void 0,c=n[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value;i=Math.max(i,r.measureText(l).width)}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}var d=12*n.length,m=(t.clientWidth-i)/2,f=(t.clientHeight-d)/2;r.fillStyle="white",r.globalAlpha=.9,r.fillRect(m-10,f-10,i+20,d+20),r.globalAlpha=1,r.strokeStyle="red",r.strokeRect(m-10,f-10,i+20,d+20),r.fillStyle="red";for(var h=0,g=0;g<n.length;g++)h+=3,r.fillText(n[g],m,f+h),h+=9}};return{get hookErrorHandler(){return e},get notifyAboutRecoveryFromUnexpectedError(){return d},get onErrorHandler(){return r},get notifyAboutKnownIssue(){return f}}}),$traceurRuntime.registerModule("src/gates/AllGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ArithmeticGates.js","src/gates/AllGates.js")).ArithmeticGates,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AmplitudeDisplay.js","src/gates/AllGates.js")).AmplitudeDisplayFamily,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/BitCountGates.js","src/gates/AllGates.js")).BitCountGates,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/BlochSphereDisplay.js","src/gates/AllGates.js")).BlochSphereDisplay,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ComparisonGates.js","src/gates/AllGates.js")).ComparisonGates,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Controls.js","src/gates/AllGates.js")).Controls,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/CountingGates.js","src/gates/AllGates.js")).CountingGates,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/CycleBitsGates.js","src/gates/AllGates.js")).CycleBitsGates,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/DensityMatrixDisplay.js","src/gates/AllGates.js")).DensityMatrixDisplayFamily,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Debug_ErrorInjectionGate.js","src/gates/AllGates.js")).ErrorInjectionGate,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ExponentiatingGates.js","src/gates/AllGates.js")).ExponentiatingGates,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/FourierTransformGates.js","src/gates/AllGates.js")).FourierTransformGates,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/HalfTurnGates.js","src/gates/AllGates.js")).HalfTurnGates,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/IncrementGates.js","src/gates/AllGates.js")).IncrementGates,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/InputGates.js","src/gates/AllGates.js")).InputGates,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/InterleaveBitsGates.js","src/gates/AllGates.js")).InterleaveBitsGates,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MeasurementGate.js","src/gates/AllGates.js")).MeasurementGate,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularIncrementGates.js","src/gates/AllGates.js")).ModularIncrementGates,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularAdditionGates.js","src/gates/AllGates.js")).ModularAdditionGates,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularMultiplicationGates.js","src/gates/AllGates.js")).ModularMultiplicationGates,R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularMultiplyAccumulateGates.js","src/gates/AllGates.js")).ModularMultiplyAccumulateGates,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MultiplicationGates.js","src/gates/AllGates.js")).MultiplicationGates,M=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MultiplyAccumulateGates.js","src/gates/AllGates.js")).MultiplyAccumulateGates,_=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Joke_NeGate.js","src/gates/AllGates.js")).NeGate,x=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ParametrizedRotationGates.js","src/gates/AllGates.js")).ParametrizedRotationGates,S=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/PhaseGradientGates.js","src/gates/AllGates.js")).PhaseGradientGates,T=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/PivotFlipGates.js","src/gates/AllGates.js")).PivotFlipGates,A=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/PostSelectionGates.js","src/gates/AllGates.js")).PostSelectionGates,C=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/PoweringGates.js","src/gates/AllGates.js")).PoweringGates,$=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ProbabilityDisplay.js","src/gates/AllGates.js")).ProbabilityDisplayFamily,j=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/QuarterTurnGates.js","src/gates/AllGates.js")).QuarterTurnGates,E=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ReverseBitsGate.js","src/gates/AllGates.js")).ReverseBitsGateFamily,I=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/SampleDisplay.js","src/gates/AllGates.js")).SampleDisplayFamily,G=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Detector.js","src/gates/AllGates.js")).Detector,P=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/SpacerGate.js","src/gates/AllGates.js")).SpacerGate,k=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/SwapGateHalf.js","src/gates/AllGates.js")).SwapGateHalf,N=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Impossible_UniversalNotGate.js","src/gates/AllGates.js")).UniversalNotGate,O=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/VariousXGates.js","src/gates/AllGates.js")).VariousXGates,D=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/VariousYGates.js","src/gates/AllGates.js")).VariousYGates,z=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/VariousZGates.js","src/gates/AllGates.js")).VariousZGates,F=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/XorGates.js","src/gates/AllGates.js")).XorGates,B=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Joke_ZeroGate.js","src/gates/AllGates.js")).ZeroGate,U=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Joke_MysteryGate.js","src/gates/AllGates.js")).MysteryGateMaker,L=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/gates/AllGates.js")).seq,W={};W.Special={Measurement:p,SwapHalf:k},W.Displays={AmplitudeDisplayFamily:t,ProbabilityDisplayFamily:$,SampleDisplayFamily:I,DensityMatrixDisplayFamily:s,BlochSphereDisplay:n},W.Arithmetic=e,W.BitCountGates=r,W.ComparisonGates=i,W.Controls=a,W.CountingGates=o,W.CycleBitsGates=u,W.Displays.DensityMatrixDisplay=s.ofSize(1),W.Displays.DensityMatrixDisplay2=s.ofSize(2),W.Displays.ChanceDisplay=W.Displays.ProbabilityDisplayFamily.ofSize(1),W.ErrorInjection=c,W.Exponentiating=l,W.FourierTransformGates=d,W.HalfTurns=m,W.IncrementGates=f,W.InputGates=h,W.InterleaveBitsGates=g,W.ModularIncrementGates=v,W.ModularAdditionGates=y,W.ModularMultiplicationGates=b,W.ModularMultiplyAccumulateGates=R,W.MultiplicationGates=w,W.MultiplyAccumulateGates=M,W.NeGate=_,W.OtherX=O,W.OtherY=D,W.OtherZ=z,W.ParametrizedRotationGates=x,W.PhaseGradientGates=S,W.PivotFlipGates=T,W.PostSelectionGates=A,W.Powering=C,W.QuarterTurns=j,W.ReverseBitsGateFamily=E,W.Detector=G,W.SpacerGate=P,W.UniversalNot=N,W.XorGates=F,W.ZeroGate=B,W.KnownToSerializer=$traceurRuntime.spread(a.all,h.all,[p,G,k,P,N,c,B,_],t.all,$.all,I.all,s.all,[n],e.all,r.all,i.all,o.all,u.all,l.all,d.all,m.all,f.all,g.all,y.all,v.all,b.all,R.all,w.all,M.all,j.all,x.all,S.all,T.all,A.all,C.all,E.all,O.all,D.all,z.all,F.all);var H=L(W.KnownToSerializer).keyedBy(function(e){return e.serializedId});return W.findKnownGateById=function(e,t){return H.has(e)?H.get(e):t.findGateWithSerializedId(e)},W.TopToolboxGroups=[{hint:"Probes",gates:[p,void 0,A.PostSelectOff,A.PostSelectOn,a.AntiControl,a.Control]},{hint:"Displays",gates:[I.ofSize(3),void 0,s.ofSize(1),n,$.ofSize(1),t.ofSize(2)]},{hint:"Half Turns",gates:[m.Z,k,m.Y,void 0,m.X,m.H]},{hint:"Quarter Turns",gates:[j.SqrtZForward,j.SqrtZBackward,j.SqrtYForward,j.SqrtYBackward,j.SqrtXForward,j.SqrtXBackward]},{hint:"Eighth Turns",gates:[z.Z4,z.Z4i,D.Y4,D.Y4i,O.X4,O.X4i]},{hint:"Sixteenths",gates:[z.Z8,z.Z8i,D.Y8,D.Y8i,O.X8,O.X8i]},{hint:"Spinning",gates:[C.ZForward,C.ZBackward,C.YForward,C.YBackward,C.XForward,C.XBackward]},{hint:"Parametrized",gates:[x.ZToA,x.ZToMinusA,x.YToA,x.YToMinusA,x.XToA,x.XToMinusA]},{hint:"Silly",gates:[B,U(),_,void 0,P,void 0]}],W.BottomToolboxGroups=[{hint:"X/Y Probes",gates:[a.XAntiControl,a.XControl,a.YAntiControl,a.YControl,A.PostSelectAntiX,A.PostSelectX,A.PostSelectAntiY,A.PostSelectY]},{hint:"Order",gates:[o.CountingFamily.ofSize(3),o.UncountingFamily.ofSize(3),E.ofSize(2),void 0,u.CycleBitsFamily.ofSize(3),u.ReverseCycleBitsFamily.ofSize(3),g.InterleaveBitsGateFamily.ofSize(6),g.DeinterleaveBitsGateFamily.ofSize(6)]},{hint:"Frequency",gates:[d.FourierTransformFamily.ofSize(2),d.InverseFourierTransformFamily.ofSize(2),void 0,void 0,S.PhaseGradientFamily.ofSize(2),S.PhaseDegradientFamily.ofSize(2),S.DynamicPhaseGradientFamily.ofSize(2),S.DynamicPhaseDegradientFamily.ofSize(2)]},{hint:"Inputs",gates:[h.InputAFamily.ofSize(2),h.SetA,h.InputBFamily.ofSize(2),h.SetB,h.InputRFamily.ofSize(2),h.SetR,void 0,void 0]},{hint:"Arithmetic",gates:[f.IncrementFamily.ofSize(2),f.DecrementFamily.ofSize(2),e.PlusAFamily.ofSize(2),e.MinusAFamily.ofSize(2),M.MultiplyAddInputsFamily.ofSize(2),M.MultiplySubtractInputsFamily.ofSize(2),w.TimesAFamily.ofSize(2),w.TimesAInverseFamily.ofSize(2)]},{hint:"Compare",gates:[i.ALessThanB,i.AGreaterThanB,i.ALessThanOrEqualToB,i.AGreaterThanOrEqualToB,i.AEqualToB,i.ANotEqualToB,void 0,void 0]},{hint:"Modular",gates:[v.IncrementModRFamily.ofSize(2),v.DecrementModRFamily.ofSize(2),y.PlusAModRFamily.ofSize(2),y.MinusAModRFamily.ofSize(2),b.TimesAModRFamily.ofSize(2),b.TimesAModRInverseFamily.ofSize(2),b.TimesBToTheAModRFamily.ofSize(2),b.TimesInverseBToTheAModRFamily.ofSize(2)]}],{get Gates(){return W}}}),$traceurRuntime.registerModule("src/gates/AmplitudeDisplay.js",[],function(){"use strict";function e(e,t,r,n){var l=new C(e);l.dontDeallocCurrentTexture();var d=S().vec2.arrayPowerSizeOfTexture(e),f=R.numberOfSetBits(t.inclusionMask),h=R.numberOfSetBits(t.inclusionMask&(1<<r)-1),p=d-f;l.shadeAndTrade(function(e){return m.controlSelect(t,e)},A.takeVec2Tex(p)),l.shadeAndTrade(function(e){return g.cycleAllBits(e,h-r)});var v=l.dontDeallocCurrentTexture();l.shadeAndTrade(i,A.takeVec4Tex(p)),a(l,n),o(l,n),l.shadeAndTrade(u);var y=l.dontDeallocCurrentTexture();return l.shadeAndTrade(function(e){return G(v,e)},A.takeVec4Tex(p)),v.deallocByDepositingInPool("ketJustAfterCycle in makeAmplitudeSpanPipeline"),s(l,n),c(l),[y,l.currentTexture]}function t(e,t,i){var a,o,u=(a=t[Symbol.iterator](),(o=a.next()).done?void 0:o.value),s=(o=a.next()).done?void 0:o.value,c=u.length>>2,l=2===c?2:1<<Math.floor(Math.round(Math.log2(c))/2),d=c/l,m=!isNaN(s[0])&&-666!==s[0],f=u[2];if(!m)return n(l,d,c,f,u);for(var h=e===i.numWires?void 0:r(u),g=void 0===h?0:Math.atan2(u[4*h+1],u[4*h]),p=Math.cos(g),v=-Math.sin(g),b=new Float32Array(2*c),R=Math.sqrt(f),w=0;w<c;w++){var M=u[4*w]/R,_=u[4*w+1]/R;b[2*w]=M*p+_*-v,b[2*w+1]=M*v+_*p}return{probabilities:void 0,superposition:new y(l,d,b),phaseLockIndex:h}}function r(e){for(var t=0,r=0,n=0;n<e.length;n+=4){var i=e[n],a=e[n+1],o=i*i+a*a;o>1e4*r&&(r=o,t=n>>2)}return t}function n(e,t,r,n,i){for(var a=new Float32Array(2*r),o=0;o<r;o++){var u=i[4*o],s=i[4*o+1];a[2*o]=Math.sqrt((u*u+s*s)/n)}return{probabilities:new y(e,t,a),superposition:void 0,phaseLockIndex:void 0}}function i(e){return $(e)}function a(e,t){for(var r=0;r<t;r++)!function(t){e.shadeAndTrade(function(e){return j(e,w.float("bit",1<<t))})}(r)}function o(e,t){for(var r=S().vec4.arrayPowerSizeOfTexture(e.currentTexture);r>t;)r-=1,e.shadeHalveAndTrade(function(e){return E(e,w.float("offset",1<<r))})}function u(e){return I(e)}function s(e,t){for(var r=S().vec4.arrayPowerSizeOfTexture(e.currentTexture),n=t;n>0;)n-=1,r-=1,e.shadeHalveAndTrade(function(e){return k(e,w.float("bit",1<<n))})}function c(e){for(var t=S().vec4.arrayPowerSizeOfTexture(e.currentTexture);t>0;)t-=1,e.shadeHalveAndTrade(N)}function l(e,t){var r=void 0,n=e.positionInCircuit,i=n.col,a=n.row,o=0!=(e.stats.circuitDefinition.colIsMeasuredMask(i)>>a&(1<<e.gate.height)-1);t?r="incoherent":o&&(r=e.gate.width<=2?"(w/ measure defer)":"(assuming measurement deferred)"),void 0!==r&&e.painter.print(r,e.rect.x+e.rect.w/2,e.rect.y+e.rect.h,"center","hanging","red","12px sans-serif",e.rect.w,e.rect.h,void 0)}var d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/AmplitudeDisplay.js")).Config,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/gates/AmplitudeDisplay.js")).CircuitShaders,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/AmplitudeDisplay.js")).Gate,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/AmplitudeDisplay.js")).GatePainting,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateShaders.js","src/gates/AmplitudeDisplay.js")).GateShaders,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/gates/AmplitudeDisplay.js")).Format,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/gates/AmplitudeDisplay.js")).MathPainter,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/AmplitudeDisplay.js")).Matrix,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/AmplitudeDisplay.js")).Point,R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/AmplitudeDisplay.js")).Util,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/AmplitudeDisplay.js")).WglArg,M=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/AmplitudeDisplay.js")).WglConfiguredShader,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/gates/AmplitudeDisplay.js"))),_=M.Inputs,x=M.Outputs,S=M.currentShaderCoder,T=M.makePseudoShaderWithInputsAndOutputAndCode,A=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/gates/AmplitudeDisplay.js")).WglTexturePool,C=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/gates/AmplitudeDisplay.js")).WglTextureTrader,$=T([_.vec2("input")],x.vec4(),"vec4 outputFor(float k) {\n vec2 ri = read_input(k);\n float mag = dot(ri, ri);\n float phase = mag == 0.0 ? 0.0 : atan(ri.y, ri.x);\n return vec4(mag, phase, mag, 0.0);\n }"),j=T([_.vec4("input")],x.vec4(),"\n uniform float bit;\n\n float xorBit(float v) {\n float b = mod(floor(v/bit), 2.0);\n float d = 1.0 - 2.0*b;\n return v + bit*d;\n }\n\n vec4 outputFor(float k) {\n float partner = xorBit(k);\n vec4 v = read_input(k);\n vec4 p = read_input(partner);\n return vec4(v.x, v.y, v.z + p.z, 0.0);\n }"),E=T([_.vec4("input")],x.vec4(),"\n uniform float offset;\n\n vec4 outputFor(float k) {\n vec4 p = read_input(k);\n vec4 q = read_input(k + offset);\n return vec4(\n p.x + q.x,\n // Bias towards p1 is to keep the choice stable in the face of uniform superpositions and noise.\n p.z*1.001 >= q.z ? p.y : q.y,\n p.z + q.z,\n 0.0);\n }"),I=T([_.vec4("input")],x.vec4(),"\n vec4 outputFor(float k) {\n vec4 polar = read_input(k);\n float mag = sqrt(polar.x);\n return vec4(mag * cos(polar.y), mag * sin(polar.y), polar.z, 0.0);\n }"),G=function(e,t){return P(e,t)},P=T([_.vec2("ket"),_.vec4("rep")],x.vec4(),"vec4 outputFor(float k) {\n return vec4(read_ket(k), read_rep(mod(k, len_rep())).xy);\n }"),k=T([_.vec4("input")],x.vec4(),"\n uniform float bit;\n\n vec2 mul(vec2 c1, vec2 c2) {\n return vec2(c1.x*c2.x - c1.y*c2.y, c1.x*c2.y + c1.y*c2.x);\n }\n vec4 mergeRatios(vec4 a, vec4 b) {\n vec2 c1 = mul(a.xy, b.zw);\n vec2 c2 = mul(a.zw, b.xy);\n vec2 d = c1 - c2;\n float err = dot(d, d);\n // The max up-scaling controls a tricky tradeoff between noisy false positives and blurry false negatives.\n err /= max(0.00000000001, min(abs(dot(c1, c1)), abs(dot(c2,c2))));\n float m1 = dot(a, a);\n float m2 = dot(b, b);\n return a.x == -666.0 || b.x == -666.0 || err > 0.001 ? vec4(-666.0, -666.0, -666.0, -666.0)\n : m1 >= m2 ? a\n : b;\n }\n\n vec4 outputFor(float k) {\n float s1 = mod(k, bit) + floor(k/bit)*2.0*bit;\n float s2 = s1 + bit;\n vec4 v1 = read_input(s1);\n vec4 v2 = read_input(s2);\n\n return mergeRatios(v1, v2);\n }"),N=T([_.vec4("input")],x.vec4(),"vec4 outputFor(float k) {\n vec4 a = read_input(k);\n vec4 b = read_input(k + len_output());\n return a.x == -666.0 || b.x == -666.0 ? vec4(-666.0, -666.0, -666.0, -666.0) : a + b;\n }"),O=h.makeDisplayDrawer(function(e){var t=e.gate.height,r=e.customStats||{probabilities:void 0,superposition:(1===t?y.zero(2,1):y.zero(1<<Math.floor(t/2),1<<Math.ceil(t/2))).times(NaN),phaseLockIndex:void 0},n=r.probabilities,i=r.superposition,a=r.phaseLockIndex,o=n||i,u=void 0===i,s=e.rect.w-e.rect.h*o.width()/o.height(),c=e.rect.skipLeft(s/2).skipRight(s/2);v.paintMatrix(e.painter,o,c,d.SUPERPOSITION_MID_COLOR,"black",d.SUPERPOSITION_FORE_COLOR,d.SUPERPOSITION_BACK_COLOR,u?"transparent":"black");var m=function(e){return(e>=0?"+":"")+e.toFixed(2)};if(u)v.paintMatrixTooltip(e.painter,o,c,e.focusPoints,function(t,r){return"Chance of |"+R.bin(r*o.width()+t,e.gate.height)+"⟩ [amplitude not defined]"},function(e,t,r){return"raw: "+(100*r.norm2()).toFixed(4)+"%, log: "+(10*Math.log10(r.norm2())).toFixed(1)+" dB"},function(e,t,r){return"[entangled with other qubits]"});else if(v.paintMatrixTooltip(e.painter,o,c,e.focusPoints,function(t,r){return"Amplitude of |"+R.bin(r*o.width()+t,e.gate.height)+"⟩"},function(e,t,r){return"val:"+r.toString(new p(!1,0,5,", "))},function(e,t,r){return"mag²:"+(100*r.norm2()).toFixed(4)+"%, phase:"+m(180*r.phase()/Math.PI)+"°"}),void 0!==a){var f=c.w/o.width(),h=c.h/o.height(),g=a%o.width(),w=Math.floor(a/o.width()),M=c.x+f*(g+.5),_=c.y+h*(w+.5);e.painter.strokeLine(new b(M,_),new b(M+f/2,_),"red",2),e.painter.print("fixed",M+.5*f,_,"right","bottom","red","12px monospace",.5*f,.5*h)}l(e,u)}),D=f.buildFamily(1,16,function(r,n){return n.setSerializedId("Amps"+r).setSymbol("Amps").setTitle("Amplitude Display").setBlurb("Shows the amplitudes of some wires, if separable.\nUse controls to see conditional amplitudes.").setWidth(1===r?2:r%2==0?r:Math.ceil(r/2)).promiseHasNoNetEffectOnStateVector().setExtraDisableReasonFinder(function(e){return e.isNested?"can't\nnest\ndisplays\n(sorry)":void 0}).setStatTexturesMaker(function(t){return e(t.stateTrader.currentTexture,t.controls,t.row,r)}).setStatPixelDataPostProcessor(function(e,n){return t(r,e,n)}).setDrawer(O)});return{get AmplitudeDisplayFamily(){return D},get amplitudesToPolarKets(){return i},get convertAwayFromPolar(){return u},get amplitudeDisplayStatTextures(){return e},get reduceToLongestPolarKet(){return o},get foldConsistentRatios(){return s},get spreadLengthAcrossPolarKets(){return a},get signallingSumAll(){return c},get toRatiosVsRepresentative(){return G}}}),$traceurRuntime.registerModule("src/gates/ArithmeticGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ArithmeticGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/ArithmeticGates.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ArithmeticGates.js")),n=r.ketArgs,i=r.ketShaderPermute,a=r.ketInputGateShaderCode,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ArithmeticGates.js")).WglArg,u={},s=function(e,t){return function(r){var n=Math.floor(e/2),i=Math.ceil(e/2),a=r&(1<<n)-1,o=r>>n;return o+=a*t,o&=(1<<i)-1,a+(o<<n)}},c=i("\n uniform float factor;\n "+a("A")+"\n ","\n float d = read_input_A();\n d *= factor;\n d = mod(d, span);\n return mod(out_id + span - d, span);");return u.Legacy_AdditionFamily=e.buildFamily(2,16,function(e,r){return r.setSerializedId("add"+e).setSymbol("b+=a").setTitle("Addition Gate").setBlurb("Adds a little-endian number into another.").setDrawer(t.SECTIONED_DRAWER_MAKER(["a","b+=a"],[Math.floor(e/2)/e])).setActualEffectToUpdateFunc(function(t){return u.PlusAFamily.ofSize(Math.ceil(e/2)).customOperation(t.withRow(t.row+Math.floor(e/2)).withInputSetToRange("A",t.row,Math.floor(e/2)))}).setKnownEffectToPermutation(s(e,1))}),u.Legacy_SubtractionFamily=e.buildFamily(2,16,function(e,r){return r.setSerializedId("sub"+e).setSymbol("b-=a").setTitle("Subtraction Gate").setBlurb("Subtracts a little-endian number from another.").setDrawer(t.SECTIONED_DRAWER_MAKER(["a","b-=a"],[Math.floor(e/2)/e])).setActualEffectToUpdateFunc(function(t){return u.MinusAFamily.ofSize(Math.ceil(e/2)).customOperation(t.withRow(t.row+Math.floor(e/2)).withInputSetToRange("A",t.row,Math.floor(e/2)))}).setKnownEffectToPermutation(s(e,-1))}),u.PlusAFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("+=A"+e).setSymbol("+A").setTitle("Addition Gate [input A]").setBlurb("Adds input A into the qubits covered by this gate.").setRequiredContextKeys("Input Range A").setActualEffectToShaderProvider(function(t){var r;return(r=c).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A"]),[o.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(t,r){return t+r&(1<<e)-1})}),u.MinusAFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("-=A"+e).setSymbol("−A").setTitle("Subtraction Gate [input A]").setBlurb("Subtracts input A out of the qubits covered by this gate.").setRequiredContextKeys("Input Range A").setActualEffectToShaderProvider(function(t){var r;return(r=c).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A"]),[o.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(t,r){return t-r&(1<<e)-1})}),u.all=$traceurRuntime.spread(u.Legacy_AdditionFamily.all,u.Legacy_SubtractionFamily.all,u.PlusAFamily.all,u.MinusAFamily.all),{get ArithmeticGates(){return u}}}),$traceurRuntime.registerModule("src/gates/BitCountGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/BitCountGates.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/BitCountGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/BitCountGates.js")),n=r.ketArgs,i=r.ketShaderPermute,a=r.ketInputGateShaderCode,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/BitCountGates.js")).Util,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/BitCountGates.js")).WglArg,s={},c=i("\n uniform float factor;\n "+a("A")+"\n ","\n float d = read_input_A();\n float popcnt = 0.0;\n for (int i = 0; i < "+e.MAX_SIMULATION_WIRE_COUNT+"; i++) {\n popcnt += mod(d, 2.0);\n d = floor(d / 2.0);\n }\n float offset = mod(popcnt * factor, span);\n return mod(out_id + span - offset, span);");return s.PlusBitCountAFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedIdAndSymbol("+cntA"+e).setSymbol("+1s(A)").setTitle("Bit Count Gate").setBlurb("Counts the number of ON bits in input A and adds that into this output.").setRequiredContextKeys("Input Range A").setActualEffectToShaderProvider(function(t){var r;return(r=c).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A"]),[u.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(t,r){return t+o.numberOfSetBits(r)&(1<<e)-1})}),s.MinusBitCountAFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedIdAndSymbol("-cntA"+e).setSymbol("-1s(A)").setTitle("Bit Un-Count Gate").setBlurb("Counts the number of ON bits in input A and subtracts that into this output.").setRequiredContextKeys("Input Range A").setActualEffectToShaderProvider(function(t){var r;return(r=c).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A"]),[u.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(t,r){return t-o.numberOfSetBits(r)&(1<<e)-1})}),s.all=$traceurRuntime.spread(s.PlusBitCountAFamily.all,s.MinusBitCountAFamily.all),{get BitCountGates(){return s}}}),$traceurRuntime.registerModule("src/gates/BlochSphereDisplay.js",[],function(){"use strict";function e(e,t,r,n,i,a){var u=t.center(),s=Math.min(t.w,t.h)/2;if(!a.every(function(e){return e.distanceTo(u)>=s})){var c=2*Math.PI,l=function(e){return(e>=0?"+":"")+(360*e/c).toFixed(2)+"°"},d=function(e){return(e>=0?"+":"")+e.toFixed(4)},m=Math.sqrt(r*r+n*n+i*i),f=Math.atan2(n,-r),h=Math.max(0,Math.PI/2-Math.atan2(-i,Math.sqrt(n*n+r*r)));e.strokeCircle(u,s,"orange",2),o.paintDeferredValueTooltip(e,u.x+s*Math.sqrt(.5),u.y-s*Math.sqrt(.5),"Bloch sphere representation of local state","r:"+d(m)+", ϕ:"+l(f)+", θ:"+l(h),"x:"+d(-r)+", y:"+d(n)+", z:"+d(-i))}}function t(e,t,r,n,i,a){var u=i.center(),s=Math.min(i.w,i.h)/2,c=o.coordinateSystem(s),l=c.dx,d=c.dy,m=c.dz,f=u.plus(l.times(t)).plus(d.times(r)).plus(m.times(n)),h=3.8/(1+t/6);e.strokeLine(u,f,"black",1.5),e.fillCircle(f,h,a),e.ctx.save(),e.ctx.globalAlpha*=Math.min(1,Math.max(0,1-t*t-r*r-n*n)),e.fillCircle(f,h,"yellow"),e.ctx.restore(),e.strokeCircle(f,h,"black"),e.ctx.save(),e.ctx.globalAlpha*=Math.min(1,Math.max(0,.5+5*t)),e.strokeLine(u,f,"black",2),e.ctx.restore()}function r(r,i,a){var s,c,l,d,m=void 0!==arguments[3]?arguments[3]:[],f=void 0!==arguments[4]?arguments[4]:n.DISPLAY_GATE_BACK_COLOR,h=void 0!==arguments[5]?arguments[5]:n.DISPLAY_GATE_FORE_COLOR,g=a.center(),p=Math.min(a.w,a.h)/2,v=o.coordinateSystem(p),y=v.dx,b=v.dy,R=v.dz;r.fillCircle(g,p,f),r.trace(function(e){e.circle(g.x,g.y,p),e.ellipse(g.x,g.y,b.x,y.y),e.ellipse(g.x,g.y,y.x,R.y);var t=!0,r=!1,n=void 0;try{for(var i=void 0,a=[y,b,R][Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e.line(g.x-o.x,g.y-o.y,g.x+o.x,g.y+o.y)}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}).thenStroke("#BBB");var w=(s=[NaN,NaN,NaN][Symbol.iterator](),(c=s.next()).done?void 0:c.value),M=(c=s.next()).done?void 0:c.value,_=(c=s.next()).done?void 0:c.value;i.hasNaN()?r.printParagraph("NaN",a,new u(.5,.5),"red"):t(r,w=(d=(l=i.qubitDensityMatrixToBlochVector()[Symbol.iterator]()).next()).done?void 0:d.value,M=(d=l.next()).done?void 0:d.value,_=(d=l.next()).done?void 0:d.value,a,h),e(r,a,w,M,_,m)}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/BlochSphereDisplay.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/BlochSphereDisplay.js")).GateBuilder,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/BlochSphereDisplay.js")).GatePainting,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/gates/BlochSphereDisplay.js")).MathPainter,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/BlochSphereDisplay.js")).Point,s=(new i).setSerializedIdAndSymbol("Bloch").setTitle("Bloch Sphere Display").setBlurb("Shows a wire's local state as a point on the Bloch Sphere.\nUse controls to see conditional states.").markAsDrawerNeedsSingleQubitDensityStats().setDrawer(a.makeDisplayDrawer(function(e){var t=e.positionInCircuit,n=t.row,i=t.col,a=e.stats.qubitDensityMatrix(i,n);r(e.painter,a,e.rect,e.focusPoints)})).promiseHasNoNetEffectOnStateVector().setExtraDisableReasonFinder(function(e){return e.isNested?"can't\nnest\ndisplays\n(sorry)":void 0}).gate;return{get paintBlochSphereDisplay(){return r},get BlochSphereDisplay(){return s}}}),$traceurRuntime.registerModule("src/gates/ComparisonGates.js",[],function(){"use strict";function e(e){var t=i("\n "+a("A")+"\n "+a("B")+"\n ","\n float lhs = read_input_A();\n float rhs = read_input_B();\n return mod(out_id + (("+e+") ? 1.0 : 0.0), 2.0);");return function(e){var r;return(r=t).withArgs.apply(r,$traceurRuntime.spread(n(e,1,["A","B"])))}}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ComparisonGates.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ComparisonGates.js")),n=r.ketArgs,i=r.ketShaderPermute,a=r.ketInputGateShaderCode,o=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/ComparisonGates.js")).WglConfiguredShader,{});return o.ALessThanB=(new t).setSerializedId("^A<B").setSymbol("⊕A<B").setTitle("Less-Than Gate").setBlurb("Toggles a qubit if input A is less than input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs < rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t<r?1:0)}).gate,o.AGreaterThanB=(new t).setSerializedId("^A>B").setSymbol("⊕A>B").setTitle("Greater-Than Gate").setBlurb("Toggles a qubit if input A is greater than input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs > rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t>r?1:0)}).gate,o.ALessThanOrEqualToB=(new t).setSerializedId("^A<=B").setSymbol("⊕A≤B").setTitle("At-Most Gate").setBlurb("Toggles a qubit if input A is at most input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs <= rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t<=r?1:0)}).gate,o.AGreaterThanOrEqualToB=(new t).setSerializedId("^A>=B").setSymbol("⊕A≥B").setTitle("At-Least Gate").setBlurb("Toggles a qubit if input A is at least input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs >= rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t>=r?1:0)}).gate,o.AEqualToB=(new t).setSerializedId("^A=B").setSymbol("⊕A=B").setTitle("Equality Gate").setBlurb("Toggles a qubit if input A is equal to input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs == rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t===r?1:0)}).gate,o.ANotEqualToB=(new t).setSerializedId("^A!=B").setSymbol("⊕A≠B").setTitle("Inequality Gate").setBlurb("Toggles a qubit if input A isn't equal to input B.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(e("lhs != rhs")).setKnownEffectToParametrizedPermutation(function(e,t,r){return e^(t!==r?1:0)}).gate,o.all=[o.ALessThanB,o.AGreaterThanB,o.AEqualToB,o.ANotEqualToB,o.ALessThanOrEqualToB,o.AGreaterThanOrEqualToB],{get ComparisonGates(){return o}}}),$traceurRuntime.registerModule("src/gates/Controls.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Controls.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Controls.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateShaders.js","src/gates/Controls.js")).GateShaders,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/HalfTurnGates.js","src/gates/Controls.js")).HalfTurnGates,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/QuarterTurnGates.js","src/gates/Controls.js")).QuarterTurnGates,a={};return a.Control=(new e).setSerializedIdAndSymbol("•").setTitle("Control").setBlurb("Conditions on a qubit being ON.\nGates in the same column only apply to states meeting the condition.").promiseHasNoNetEffectOnStateVector().markAsControlExpecting(!0).setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e)),e.painter.fillCircle(e.rect.center(),5,"black")}).gate,a.AntiControl=(new e).setSerializedIdAndSymbol("◦").setTitle("Anti-Control").setBlurb("Conditions on a qubit being OFF.\nGates in the same column only apply to states meeting the condition.").promiseHasNoNetEffectOnStateVector().markAsControlExpecting(!1).setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e));var r=e.rect.center();e.painter.fillCircle(r,5),e.painter.strokeCircle(r,5)}).gate,a.XAntiControl=(new e).setSerializedId("⊕").setSymbol("⊖").setTitle("X-Axis Anti-Control").setBlurb("Conditions on a qubit being ON+OFF.\nGates in the same column only apply to states meeting the condition.").markAsControlExpecting(!1).setSetupCleanupEffectToUpdateFunc(n.H.customOperation,n.H.customOperation).setActualEffectToUpdateFunc(function(){}).promiseEffectIsStable().setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e));var r=e.rect.center();e.painter.fillCircle(r,5),e.painter.strokeCircle(r,5),e.painter.strokeLine(r.offsetBy(-5,0),r.offsetBy(5,0))}).gate,a.XControl=(new e).setSerializedId("⊖").setSymbol("⊕").setTitle("X-Axis Control").setBlurb("Conditions on a qubit being ON-OFF.\nGates in the same column only apply to states meeting the condition.").markAsControlExpecting(!0).setSetupCleanupEffectToUpdateFunc(n.H.customOperation,n.H.customOperation).setActualEffectToUpdateFunc(function(){}).promiseEffectIsStable().setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e));var r=e.rect.center();e.painter.fillCircle(r,5),e.painter.strokeCircle(r,5),e.painter.strokeLine(r.offsetBy(0,-5),r.offsetBy(0,5)),e.painter.strokeLine(r.offsetBy(-5,0),r.offsetBy(5,0))}).gate,a.YAntiControl=(new e).setSerializedId("⊗").setSymbol("(/)").setTitle("Y-Axis Anti-Control").setBlurb("Conditions on a qubit being ON+iOFF.\nGates in the same column only apply to states meeting the condition.").markAsControlExpecting(!1).setSetupCleanupEffectToUpdateFunc(function(e){return r.applyMatrixOperation(e,i.SqrtXForward._knownMatrix)},function(e){return r.applyMatrixOperation(e,i.SqrtXBackward._knownMatrix)}).setActualEffectToUpdateFunc(function(){}).promiseEffectIsStable().setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e));var r=e.rect.center();e.painter.fillCircle(r,5),e.painter.strokeCircle(r,5);var n=5*Math.sqrt(.5)*1.1;e.painter.strokeLine(r.offsetBy(+n,-n),r.offsetBy(-n,+n)),(e.isInToolbox||e.isHighlighted)&&t.paintOutline(e)}).gate,a.YControl=(new e).setSerializedId("(/)").setSymbol("⊗").setTitle("Y-Axis Control").setBlurb("Conditions on a qubit being ON-iOFF.\nGates in the same column only apply to states meeting the condition.").markAsControlExpecting(!0).setSetupCleanupEffectToUpdateFunc(function(e){return r.applyMatrixOperation(e,i.SqrtXForward._knownMatrix)},function(e){return r.applyMatrixOperation(e,i.SqrtXBackward._knownMatrix)}).setActualEffectToUpdateFunc(function(){}).promiseEffectIsStable().setDrawer(function(e){(e.isInToolbox||e.isHighlighted)&&(t.paintBackground(e),t.paintOutline(e));var r=e.rect.center();e.painter.fillCircle(r,5),e.painter.strokeCircle(r,5);var n=5*Math.sqrt(.5);e.painter.strokeLine(r.offsetBy(+n,+n),r.offsetBy(-n,-n)),e.painter.strokeLine(r.offsetBy(+n,-n),r.offsetBy(-n,+n)),(e.isInToolbox||e.isHighlighted)&&t.paintOutline(e)}).gate,a.all=[a.Control,a.AntiControl,a.XAntiControl,a.XControl,a.YAntiControl,a.YControl],{get Controls(){return a}}}),$traceurRuntime.registerModule("src/gates/CountingGates.js",[],function(){"use strict";function e(e,t,r,n){return n+Math.floor(e*(1<<r))*t&(1<<r)-1}function t(e,t,r,n){var i=Math.floor(e*r)*t;return f(i,r)(n)}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/CountingGates.js")).Config,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/CountingGates.js")),i=n.Gate,a=n.GateBuilder,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/CountingGates.js")).GatePainting,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/CountingGates.js")).Matrix,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/CountingGates.js")).Point,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/CountingGates.js")).ketArgs,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/CountingGates.js")).WglArg,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/IncrementGates.js","src/gates/CountingGates.js")).offsetShader,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/CycleBitsGates.js","src/gates/CountingGates.js")),f=m.makeCycleBitsPermutation,h=m.cycleBitsShader,g={},p=function(e){e=Math.min(128,e);for(var t=[],r=0;r<e;r++){var n=r/e,i=r/(e-1);e<128&&t.push(new s(n,i)),t.push(new s(n+1/e,i))}return t},v=function(e,t){var n=void 0!==arguments[2]&&arguments[2];return function(i){var a,u,c,l;if(o.MAKE_HIGHLIGHTED_DRAWER(r.TIME_DEPENDENT_HIGHLIGHT_COLOR)(i),!i.isInToolbox||i.isHighlighted){var d=(i.stats.time+e)%1,m=i.rect.y+3,f=i.rect.bottom(),h=i.rect.bottom()-3;n||(c=[h,m][Symbol.iterator](),m=(l=c.next()).done?void 0:l.value,h=(l=c.next()).done?void 0:l.value,f=i.rect.y);var g=i.rect.x,v=i.rect.right(),y=function(e){return Math.min(Math.max(g+(v-g)*e,g),v)},b=function(e){return h+(m-h)*e},R=[];R.push(new s(g,f)),(a=R).push.apply(a,$traceurRuntime.spread(p(t).map(function(e){return new s(y(e.x-d),b(e.y))}))),(u=R).push.apply(u,$traceurRuntime.spread(p(t).map(function(e){return new s(y(e.x+1-d),b(e.y))}))),R.push(new s(v,f)),i.painter.ctx.save(),i.painter.ctx.globalAlpha*=.3,i.painter.fillPolygon(R,"yellow");for(var w=1;w<R.length-2;w++)i.painter.strokeLine(R[w],R[w+1],"black");2===t&&d<.5&&(i.painter.fillRect(i.rect,"white"),i.painter.fillRect(i.rect,"white"),i.painter.fillRect(i.rect,"white")),i.painter.ctx.restore()}}};return g.ClockPulseGate=(new a).setSerializedIdAndSymbol("X^⌈t⌉").setTitle("Clock Pulse Gate").setBlurb("Xors a square wave into the target wire.").setDrawer(v(0,2)).setEffectToTimeVaryingMatrix(function(e){return e%1<.5?u.identity(2):u.PAULI_X}).promiseEffectOnlyPermutesAndPhases().gate,g.QuarterPhaseClockPulseGate=(new a).setSerializedIdAndSymbol("X^⌈t-¼⌉").setTitle("Clock Pulse Gate (Quarter Phase)").setBlurb("Xors a quarter-phased square wave into the target wire.").setDrawer(v(.75,2)).setEffectToTimeVaryingMatrix(function(e){return(e+.75)%1<.5?u.identity(2):u.PAULI_X}).promiseEffectOnlyPermutesAndPhases().gate,g.CountingFamily=i.buildFamily(1,16,function(t,r){return r.setSerializedId("Counting"+t).setSymbol("+⌈t⌉").setTitle("Counting Gate").setBlurb("Adds an increasing little-endian count into a block of qubits.").setDrawer(v(0,1<<t)).setActualEffectToShaderProvider(function(e){var r;return(r=d).withArgs.apply(r,$traceurRuntime.spread(c(e,t),[l.float("amount",Math.floor(e.time*(1<<t)))]))}).setKnownEffectToTimeVaryingPermutation(function(r,n){return e(r,1,t,n)})}),g.UncountingFamily=i.buildFamily(1,16,function(t,r){return r.setSerializedId("Uncounting"+t).setSymbol("-⌈t⌉").setTitle("Down Counting Gate").setBlurb("Subtracts an increasing little-endian count from a block of qubits.").setDrawer(v(0,1<<t,!0)).setActualEffectToShaderProvider(function(e){var r;return(r=d).withArgs.apply(r,$traceurRuntime.spread(c(e,t),[l.float("amount",-Math.floor(e.time*(1<<t)))]))}).setKnownEffectToTimeVaryingPermutation(function(r,n){return e(r,-1,t,n)})}),g.RightShiftRotatingFamily=i.buildFamily(2,16,function(e,r){return r.setSerializedId(">>t"+e).setSymbol("↟⌈t⌉").setTitle("Right-Shift Cycling Gate").setBlurb("Right-rotates a block of bits by more and more.").setDrawer(v(0,e,!0)).setActualEffectToShaderProvider(function(t){return h(t,e,-Math.floor(t.time*e))}).setKnownEffectToTimeVaryingPermutation(function(r,n){return t(r,-1,e,n)})}),g.LeftShiftRotatingFamily=i.buildFamily(2,16,function(e,r){return r.setSerializedId("<<t"+e).setSymbol("↡⌈t⌉").setTitle("Left-Shift Cycling Gate").setBlurb("Left-rotates a block of bits by more and more.").setDrawer(v(0,e)).setActualEffectToShaderProvider(function(t){return h(t,e,Math.floor(t.time*e))}).setKnownEffectToTimeVaryingPermutation(function(r,n){return t(r,1,e,n)})}),g.all=$traceurRuntime.spread([g.ClockPulseGate,g.QuarterPhaseClockPulseGate],g.CountingFamily.all,g.UncountingFamily.all,g.RightShiftRotatingFamily.all,g.LeftShiftRotatingFamily.all),{get CountingGates(){return g}}}),$traceurRuntime.registerModule("src/gates/CycleBitsGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/CycleBitsGates.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/CycleBitsGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/CycleBitsGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/CycleBitsGates.js")),i=n.ketArgs,a=n.ketShaderPermute,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/CycleBitsGates.js")).Matrix,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/CycleBitsGates.js")).Point,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/CycleBitsGates.js")).Util,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/CycleBitsGates.js")).WglArg,l=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/CycleBitsGates.js")).WglConfiguredShader,{}),d=function(e,t,r){var n;return(n=m).withArgs.apply(n,$traceurRuntime.spread(i(e,t),[c.float("amount",1<<s.properMod(-r,t))]))},m=a("uniform float amount;","out_id *= amount; return mod(out_id, span) + floor(out_id / span);"),f=function(e,t){return function(r){return e=s.properMod(e,t),r<<e&(1<<t)-1|r>>t-e}},h=function(e,t){return o.generateTransition(1<<t,f(e,t))},g=function(t){return function(n){if(void 0===n.positionInCircuit){r.paintBackground(n),r.paintOutline(n),r.paintResizeTab(n);for(var i=n.rect.x+6,a=n.rect.right()-6,o=n.rect.center().y-e.GATE_RADIUS+6,s=2*(e.GATE_RADIUS-6)/2,c=0;c<3;c++){var l=o+c*s,d=o+(c+(t?2:1))%3*s;n.painter.strokePath([new u(i,l),new u(i+8,l),new u(a-8,d),new u(a,d)])}}else r.PERMUTATION_DRAWER(n)}};return l.CycleBitsFamily=t.buildFamily(2,16,function(e,t){return t.setSerializedId("<<"+e).setSymbol("<<<").setTitle("Left Rotate").setBlurb("Rotates bits downward.").setDrawer(g(!1)).setTooltipMatrixFunc(function(){return h(1,e)}).setActualEffectToShaderProvider(function(t){return d(t,e,1)}).setKnownEffectToBitPermutation(function(t){return(t+1)%e})}),l.ReverseCycleBitsFamily=t.buildFamily(2,16,function(e,t){return t.setSerializedId(">>"+e).setSymbol(">>>").setTitle("Right Rotate").setBlurb("Rotates bits upward.").setDrawer(g(!0)).setTooltipMatrixFunc(function(){return h(-1,e)}).setActualEffectToShaderProvider(function(t){return d(t,e,-1)}).setKnownEffectToBitPermutation(function(t){return(t+e-1)%e})}),l.all=$traceurRuntime.spread(l.CycleBitsFamily.all,l.ReverseCycleBitsFamily.all),{get CycleBitsGates(){return l},get cycleBitsShader(){return d},get makeCycleBitsPermutation(){return f}}}),$traceurRuntime.registerModule("src/gates/Debug_ErrorInjectionGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/gates/Debug_ErrorInjectionGate.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Debug_ErrorInjectionGate.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Debug_ErrorInjectionGate.js")).GatePainting,n=(new t).setSerializedId("__error__").setSymbol("ERR!").setTitle("Error Injection Gate").setBlurb("Throws an exception during circuit stat computations, for testing error paths.").setDrawer(r.MAKE_HIGHLIGHTED_DRAWER("red","red")).setActualEffectToUpdateFunc(function(t){throw new e("Applied an Error Injection Gate",{qubit:t.row})}).promiseEffectIsStable().gate;return{get ErrorInjectionGate(){return n}}}),$traceurRuntime.registerModule("src/gates/DensityMatrixDisplay.js",[],function(){"use strict";function e(e,t,r,n,i){var a=new M(e);a.dontDeallocCurrentTexture();var u=b().vec2.arrayPowerSizeOfTexture(e),s=h.numberOfSetBits(r.inclusionMask),c=h.numberOfSetBits(r.inclusionMask&(1<<n)-1);a.shadeAndTrade(function(e){return o.controlSelect(r,e)},w.takeVec2Tex(u-s)),a.shadeAndTrade(function(e){return l.cycleAllBits(e,c-n)});var d=t-s+i;for(a.shadeAndTrade(function(e){return _(e,i)},w.takeVec2Tex(d));d>2*i;)d--,a.shadeHalveAndTrade(f.sumFoldVec2);return b().vec2.needRearrangingToBeInVec4Format&&a.shadeHalveAndTrade(f.packVec2IntoVec4),a.currentTexture}function t(e,t){if(0===t)return e;for(var r=new Float32Array(e.rawBuffer()),n=e.width(),i=0;i<n;i++)for(var a=0;a<n;a++)if(0!=((i^a)&t)){var o=2*(i*n+a);r[o]=0,r[o+1]=0}return new m(n,n,r)}function r(e,r,n,i){for(var a=e.length>>1,o=Math.round(Math.sqrt(a)),u=0,s=0;s<o;s++)u+=e[2*s*(o+1)];if(isNaN(u)||u<1e-6)return m.zero(o,o).times(NaN);for(var c=0;c<e.length;c++)e[c]/=u;var l=r.colIsMeasuredMask(n)>>i;return t(new m(o,o,e),l)}function n(e){return e.setSymbol("Density").setTitle("Density Matrix Display").setBlurb("Shows the density matrix of the local mixed state of some wires.\nUse controls to see conditional states.").promiseHasNoNetEffectOnStateVector().setExtraDisableReasonFinder(function(e){return e.isNested?"can't\nnest\ndisplays\n(sorry)":void 0})}function i(e){return n(e).setSerializedId("Density").markAsDrawerNeedsSingleQubitDensityStats().setDrawer(c.makeDisplayDrawer(function(e){var t=e.positionInCircuit,r=t.col,n=t.row,i=e.stats.qubitDensityMatrix(r,n);d.paintDensityMatrix(e.painter,i,e.rect,e.focusPoints)}))}function a(t,i){return n(i).setSerializedId("Density"+t).setWidth(t).setDrawer(S).setStatTexturesMaker(function(r){return e(r.stateTrader.currentTexture,r.wireCount,r.controls,r.row,t)}).setStatPixelDataPostProcessor(r)}var o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/gates/DensityMatrixDisplay.js")).CircuitShaders,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/DensityMatrixDisplay.js")),s=u.Gate,c=(u.GateBuilder,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/DensityMatrixDisplay.js")).GatePainting),l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateShaders.js","src/gates/DensityMatrixDisplay.js")).GateShaders,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/gates/DensityMatrixDisplay.js")).MathPainter,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/DensityMatrixDisplay.js")).Matrix,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/gates/DensityMatrixDisplay.js")).Shaders,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/DensityMatrixDisplay.js")).Util,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/DensityMatrixDisplay.js")).WglArg,p=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/DensityMatrixDisplay.js")).WglConfiguredShader,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/gates/DensityMatrixDisplay.js"))),v=p.Inputs,y=p.Outputs,b=p.currentShaderCoder,R=p.makePseudoShaderWithInputsAndOutputAndCode,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/gates/DensityMatrixDisplay.js")).WglTexturePool,M=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/gates/DensityMatrixDisplay.js")).WglTextureTrader,_=function(e,t){return x(e,g.float("qubitSpan",1<<t))},x=R([v.vec2("input")],y.vec2(),"\n uniform float qubitSpan;\n\n vec2 outputFor(float k) {\n float k_ket = mod(k, qubitSpan);\n float k_bra = mod(floor(k / qubitSpan), qubitSpan);\n float k_rest = floor(k / qubitSpan / qubitSpan);\n float offset = k_rest*qubitSpan;\n\n vec2 ampKet = read_input(k_ket + offset);\n vec2 ampBra = read_input(k_bra + offset);\n float r = dot(ampKet, ampBra);\n float i = dot(ampKet, vec2(-ampBra.y, ampBra.x));\n\n return vec2(r, i);\n }"),S=c.makeDisplayDrawer(function(e){var t=e.gate.height,r=e.customStats||m.zero(1<<t,1<<t).times(NaN);d.paintDensityMatrix(e.painter,r,e.rect,e.focusPoints)}),T=s.buildFamily(1,8,function(e,t){return 1===e?i(t):a(e,t)});return{get DensityMatrixDisplayFamily(){return T},get amplitudesToCouplings(){return _}}}),$traceurRuntime.registerModule("src/gates/Detector.js",[],function(){"use strict";function e(e,t){var r=s().vec2.arrayPowerSizeOfTexture(e.stateTrader.currentTexture);return l.controlMask(t).toBoolTexture(r)}function t(e,t){void 0!==arguments[2]&&arguments[2];var r=s().vec2.arrayPowerSizeOfTexture(e),u=new a(e);u.dontDeallocCurrentTexture(),u.shadeAndTrade(function(e){return n(e,t)},i.takeVecFloatTex(r));for(var c=s().vec2.arrayPowerSizeOfTexture(e);c>0;)c-=1,u.shadeHalveAndTrade(o.sumFoldFloat);return u.shadeAndTrade(o.packFloatIntoVec4,i.takeVec4Tex(0)),u.currentTexture}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Detector.js")).GateBuilder,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ProbabilityDisplay.js","src/gates/Detector.js")).amplitudesToProbabilities,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/gates/Detector.js")).WglTexturePool,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/gates/Detector.js")).WglTextureTrader,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/gates/Detector.js")).Shaders,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/gates/Detector.js")),s=u.currentShaderCoder,c=u.Inputs,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitShaders.js","src/gates/Detector.js")).CircuitShaders,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Controls.js","src/gates/Detector.js")).Controls,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/Detector.js")).WglArg,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/Detector.js")).Config,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Detector.js")).GatePainting,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/gates/Detector.js")),p=g.makePseudoShaderWithInputsAndOutputAndCode,v=g.Outputs,y=p([c.float("total_weight"),c.float("detection_weight"),c.bool("classification"),c.vec2("ket")],v.vec2(),"\n uniform float rnd;\n \n vec2 outputFor(float k) {\n float detectChance = read_detection_weight(0.0) / read_total_weight(0.0);\n float detection_type = float(rnd < detectChance);\n float own_type = read_classification(k);\n return read_ket(k) * float(detection_type == own_type);\n }\n "),b=(new r).setSerializedIdAndSymbol("Detector").setTitle("Detector").setBlurb("Makes a *click* when the target qubit is ON and all controls are satisfied.\nMeasures whether to click, samples the result, then post-selects on it.").setDrawer(function(e){(e.isHighlighted||e.isInToolbox)&&(e.painter.fillRect(e.rect,e.isHighlighted?f.HIGHLIGHTED_GATE_FILL_COLOR:f.TIME_DEPENDENT_HIGHLIGHT_COLOR),h.paintOutline(e));var t=2*Math.PI,r=.4*e.rect.w,n=e.rect.center(),i=n.x,a=n.y;i-=.5*r,i+=.5,a+=.5,e.painter.trace(function(e){e.ctx.arc(i,a,r,3*t/4,t/4),e.ctx.lineTo(i,a-r-1)}).thenStroke("black",2).thenFill(f.TIME_DEPENDENT_HIGHLIGHT_COLOR),e.customStats&&(e.painter.ctx.save(),e.painter.ctx.translate(e.rect.center().x,e.rect.center().y),e.painter.ctx.rotate(t/8),e.painter.ctx.strokeStyle="white",e.painter.ctx.lineWidth=2,e.painter.print("*click*",0,0,"center","middle","black","bold 16px sans-serif",1.4*e.rect.w,1.4*e.rect.h,void 0,!0),e.painter.ctx.restore())}).promiseEffectIsDiagonal().markAsReachingOtherWires().setActualEffectToUpdateFunc(function(r){var n=e(r,d.NONE),i=e(r,r.controls.and(d.bit(r.row,!0))),a=t(r.stateTrader.currentTexture,n),o=t(r.stateTrader.currentTexture,i);r.applyOperation(y(a,o,i,r.stateTrader.currentTexture,m.float("rnd",Math.random()))),o.deallocByDepositingInPool(),a.deallocByDepositingInPool(),i.deallocByDepositingInPool(),n.deallocByDepositingInPool()}).setStatTexturesMaker(function(r){var n=e(r,r.controls.and(d.bit(r.row,!0)));try{return t(r.stateTrader.currentTexture,n,!0)}finally{n.deallocByDepositingInPool("textureWithTotalWeightMatchingPositiveMeasurement:mask")}}).setStatPixelDataPostProcessor(function(e,t,r,n){return e[0]>0}).gate;return{get Detector(){return b}}}),$traceurRuntime.registerModule("src/gates/ExponentiatingGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ExponentiatingGates.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/ExponentiatingGates.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/ExponentiatingGates.js")).Matrix,n={},i=2*Math.PI,a=function(e){var t=Math.cos(i*e),n=Math.sin(i*e);return new r(2,2,new Float32Array([t,0,0,-n,0,-n,t,0]))},o=function(e){var t=Math.cos(i*e),n=Math.sin(i*e);return new r(2,2,new Float32Array([t,0,-n,0,n,0,t,0]))},u=function(e){var t=Math.cos(i*e),n=Math.sin(i*e);return new r(2,2,new Float32Array([t,-n,0,0,0,0,t,n]))};return n.XForward=(new e).setSerializedIdAndSymbol("e^-iXt").setTitle("X-Exponentiating Gate (forward)").setBlurb("Right-hand rotation around the X axis.\nPasses through ±iX instead of X.").setDrawer(t.makeCycleDrawer(1,1,2)).setEffectToTimeVaryingMatrix(a).promiseEffectIsUnitary().gate,n.XBackward=(new e).setSerializedIdAndSymbol("e^iXt").setTitle("X-Exponentiating Gate (backward)").setBlurb("Left-hand rotation around the X axis.\nPasses through ±iX instead of X.").setDrawer(t.makeCycleDrawer(-1,1,2)).setEffectToTimeVaryingMatrix(function(e){return a(-e)}).promiseEffectIsUnitary().gate,n.YForward=(new e).setSerializedIdAndSymbol("e^-iYt").setTitle("Y-Exponentiating Gate (forward)").setBlurb("Right-hand rotation around the Y axis.\nPasses through ±iY instead of Y.").setDrawer(t.makeCycleDrawer(.5,1,2)).setEffectToTimeVaryingMatrix(o).promiseEffectIsUnitary().gate,n.YBackward=(new e).setSerializedIdAndSymbol("e^iYt").setTitle("Y-Exponentiating Gate (backward)").setBlurb("Left-hand rotation around the Y axis.\nPasses through ±iY instead of Y.").setDrawer(t.makeCycleDrawer(-.5,1,2)).setEffectToTimeVaryingMatrix(function(e){return o(-e)}).promiseEffectIsUnitary().gate,n.ZForward=(new e).setSerializedIdAndSymbol("e^-iZt").setTitle("Z-Exponentiating Gate (forward)").setBlurb("Right-hand rotation around the Z axis.\nPasses through ±iZ instead of Z.").setDrawer(t.makeCycleDrawer(-1,-.5,2)).setEffectToTimeVaryingMatrix(u).promiseEffectOnlyPhases().gate,n.ZBackward=(new e).setSerializedIdAndSymbol("e^iZt").setTitle("Z-Exponentiating Gate (backward)").setBlurb("Left-hand rotation around the Z axis.\nPasses through ±iZ instead of Z.").setDrawer(t.makeCycleDrawer(1,-.5,2)).setEffectToTimeVaryingMatrix(function(e){return u(-e)}).promiseEffectOnlyPhases().gate,n.all=[n.XBackward,n.YBackward,n.ZBackward,n.XForward,n.YForward,n.ZForward],{get ExponentiatingGates(){return n}}}),$traceurRuntime.registerModule("src/gates/FourierTransformGates.js",[],function(){"use strict";function e(e,t){var r,n=void 0!==arguments[2]?arguments[2]:1;e.applyOperation((r=m).withArgs.apply(r,$traceurRuntime.spread(o(e,t),[d.float("factor",n)])))}function t(t,r){r>1&&t.applyOperation(l(r));for(var n=0;n<r;n++)n>0&&e(t,n+1,1),c.H.customOperation(t.withRow(t.row+n))}function r(t,r){for(var n=r-1;n>=0;n--)c.H.customOperation(t.withRow(t.row+n)),n>0&&e(t,n+1,-1);r>1&&t.applyOperation(l(r))}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/gates/FourierTransformGates.js")).Complex,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/FourierTransformGates.js")).Gate,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/FourierTransformGates.js")),o=a.ketArgs,u=a.ketShaderPhase,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/FourierTransformGates.js")).Matrix,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/HalfTurnGates.js","src/gates/FourierTransformGates.js")).HalfTurnGates,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ReverseBitsGate.js","src/gates/FourierTransformGates.js")).reverseShaderForSize,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/FourierTransformGates.js")).WglArg,m=u("uniform float factor;","\n float hold = floor(out_id * 2.0 / span);\n float step = mod(out_id, span / 2.0);\n return hold * step * factor * 6.2831853071795864769 / span;\n "),f=function(e){return s.generate(1<<e,1<<e,function(t,r){return n.polar(Math.pow(.5,e/2),2*Math.PI*t*r/(1<<e))})},h=function(e){return f(e).adjoint()},g={};return g.FourierTransformFamily=i.buildFamily(1,16,function(e,r){return r.setSerializedId("QFT"+e).setSymbol("QFT").setTitle("Fourier Transform Gate").setBlurb("Transforms to/from phase frequency space.").setActualEffectToUpdateFunc(function(r){return t(r,e)}).promiseEffectIsUnitary().setTooltipMatrixFunc(function(){return f(e)})}),g.InverseFourierTransformFamily=i.buildFamily(1,16,function(e,t){return t.setSerializedId("QFT†"+e).setSymbol("QFT^†").setTitle("Inverse Fourier Transform Gate").setBlurb("Transforms from/to phase frequency space.").setActualEffectToUpdateFunc(function(t){return r(t,e)}).promiseEffectIsUnitary().setTooltipMatrixFunc(function(){return h(e)})}),g.all=$traceurRuntime.spread(g.FourierTransformFamily.all,g.InverseFourierTransformFamily.all),{get applyControlledPhaseGradient(){return e},get FourierTransformGates(){return g}}}),$traceurRuntime.registerModule("src/gates/HalfTurnGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/HalfTurnGates.js")),t=(e.Gate,e.GateBuilder),r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/HalfTurnGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/HalfTurnGates.js")).Matrix,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/HalfTurnGates.js")).Point,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/HalfTurnGates.js")),o=a.ketArgs,u=a.ketShader,s={},c=(0,a.ketShaderPermute)("","return 1.0-out_id;",1);s.X=(new t).setSerializedIdAndSymbol("X").setTitle("Pauli X Gate").setBlurb("The NOT gate.\nToggles between ON and OFF.").setDrawer(function(e){if(e.isHighlighted)r.DEFAULT_DRAWER(e);else{void 0===e.positionInCircuit&&(r.paintBackground(e),r.paintOutline(e));var t=e.rect.scaledOutwardBy(.6);e.painter.fillCircle(t.center(),t.w/2),e.painter.strokeCircle(t.center(),t.w/2);var n=void 0!==e.positionInCircuit&&e.stats.circuitDefinition.colHasSingleWireControl(e.positionInCircuit.col),a=void 0!==e.positionInCircuit&&e.stats.circuitDefinition.colHasDoubleWireControl(e.positionInCircuit.col);!n&&a||e.painter.strokeLine(t.topCenter(),t.bottomCenter()),a&&(e.painter.strokeLine(t.topCenter().offsetBy(-1,0),t.bottomCenter().offsetBy(-1,0)),e.painter.strokeLine(t.topCenter().offsetBy(1,0),t.bottomCenter().offsetBy(1,0))),void 0!==e.positionInCircuit&&e.stats.circuitDefinition.locIsMeasured(new i(e.positionInCircuit.col,e.positionInCircuit.row))?(e.painter.strokeLine(t.centerLeft().offsetBy(0,-1),t.centerRight().offsetBy(0,-1)),e.painter.strokeLine(t.centerLeft().offsetBy(0,1),t.centerRight().offsetBy(0,1))):e.painter.strokeLine(t.centerLeft(),t.centerRight())}}).setActualEffectToShaderProvider(function(e){var t;return(t=c).withArgs.apply(t,$traceurRuntime.spread(o(e)))}).setKnownEffectToMatrix(n.PAULI_X).gate;var l=u("","vec2 v = inp(1.0-out_id); return (out_id*2.0 - 1.0)*vec2(-v.y, v.x);",1);s.Y=(new t).setSerializedIdAndSymbol("Y").setTitle("Pauli Y Gate").setBlurb("A combination of the X and Z gates.").setActualEffectToShaderProvider(function(e){var t;return(t=l).withArgs.apply(t,$traceurRuntime.spread(o(e)))}).setKnownEffectToMatrix(n.PAULI_Y).gate;var d=u("","return amp*(1.0 - out_id*2.0);",1);s.Z=(new t).setSerializedIdAndSymbol("Z").setTitle("Pauli Z Gate").setBlurb("The phase flip gate.\nNegates phases when the qubit is ON.").setActualEffectToShaderProvider(function(e){var t;return(t=d).withArgs.apply(t,$traceurRuntime.spread(o(e)))}).setKnownEffectToMatrix(n.PAULI_Z).gate;var m=u("","return 0.7071067811865476*(amp*(1.0-2.0*out_id) + inp(1.0-out_id));",1);return s.H=(new t).setSerializedIdAndSymbol("H").setTitle("Hadamard Gate").setBlurb("Creates simple superpositions.\nMaps ON to ON + OFF.\nMaps OFF to ON - OFF.").setActualEffectToShaderProvider(function(e){var t;return(t=m).withArgs.apply(t,$traceurRuntime.spread(o(e)))}).setKnownEffectToMatrix(n.HADAMARD).gate,s.all=[s.X,s.Y,s.Z,s.H],{get HalfTurnGates(){return s}}}),$traceurRuntime.registerModule("src/gates/Impossible_UniversalNotGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Impossible_UniversalNotGate.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/Impossible_UniversalNotGate.js")),r=t.ketArgs,n=t.ketShader,i=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/Impossible_UniversalNotGate.js")).WglConfiguredShader,function(e){var t;return(t=a).withArgs.apply(t,$traceurRuntime.spread(r(e)))}),a=n("","vec2 other = inp(1.0 - out_id); return vec2(other.x, -other.y) * (1.0 - 2.0 * out_id);",1),o=(new e).setSerializedId("__unstable__UniversalNot").setSymbol("UniNot").setTitle("Universal Not Gate").setBlurb("Mirrors through the origin of the Bloch sphere.\nImpossible in practice.").setActualEffectToShaderProvider(i).promiseEffectIsStable().gate;return{get universalNot(){return i},get UniversalNotGate(){return o}}}),$traceurRuntime.registerModule("src/gates/IncrementGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/IncrementGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/IncrementGates.js")),r=t.ketArgs,n=t.ketShaderPermute,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/IncrementGates.js")).WglArg,a={},o=n("uniform float amount;","return mod(out_id - amount + span, span);");return a.IncrementFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("inc"+e).setSymbol("+1").setTitle("Increment Gate").setBlurb("Adds 1 to the little-endian number represented by a block of qubits.").setActualEffectToShaderProvider(function(t){var n;return(n=o).withArgs.apply(n,$traceurRuntime.spread(r(t,e),[i.float("amount",1)]))}).setKnownEffectToPermutation(function(t){return t+1&(1<<e)-1})}),a.DecrementFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("dec"+e).setSymbol("−1").setTitle("Decrement Gate").setBlurb("Subtracts 1 from the little-endian number represented by a block of qubits.").setActualEffectToShaderProvider(function(t){var n;return(n=o).withArgs.apply(n,$traceurRuntime.spread(r(t,e),[i.float("amount",-1)]))}).setKnownEffectToPermutation(function(t){return t-1&(1<<e)-1})}),a.all=$traceurRuntime.spread(a.IncrementFamily.all,a.DecrementFamily.all),{get IncrementGates(){return a},get offsetShader(){return o}}}),$traceurRuntime.registerModule("src/gates/InputGates.js",[],function(){"use strict";function e(e,t,r){i.paintBackground(e,"#DDD","#DDD"),e.isInToolbox?i.paintOutline(e):e.painter.strokeRect(e.rect,"#888"),i.paintResizeTab(e);var n=e.rect.center(),a=n.x,o=n.y;e.painter.print("input",a,o-2,"center","bottom","black","16px sans-serif",e.rect.w-2,e.rect.h/2),e.painter.print(t+(r?"[::-1]":""),a,o+2,"center","top","black","16px sans-serif",e.rect.w-2,e.rect.h/2)}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/InputGates.js")),r=t.Gate,n=t.GateBuilder,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/InputGates.js")).GatePainting,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ReverseBitsGate.js","src/gates/InputGates.js")).reverseShaderForSize,o={},u=function(t,n){return r.buildFamily(1,16,function(r,i){return i.setSerializedId((n?"rev":"")+"input"+t+r).setSymbol((n?"rev ":"")+"input "+t).setTitle("Input Gate ["+t+"]"+(n?" [reversed]":"")).setBlurb("Temporarily uses some qubits as input "+t+(n?", in big-endian order":"")+".").setDrawer(function(r){return e(r,t,n)}).promiseHasNoNetEffectOnStateVector().markAsNotInterestedInControls().setSetupCleanupEffectsToShaderProviders(n&&r>1?a(r):void 0,n&&r>1?a(r):void 0).setContextProvider(function(e){return[{key:"Input Range "+t,val:{offset:e,length:r}}]})})},s=function(e){return(new n).setSerializedIdAndSymbol("set"+e).setTitle("Set Default "+e).setBlurb("Sets a default value for input "+e+", for when an inline input isn't given.").setWidth(2).setHeight(2).promiseHasNoNetEffectOnStateVector().markAsNotInterestedInControls().markAsReachingOtherWires().setStickyContextProvider(function(t,r){return[{key:"Input Default "+e,val:r.param,sticky:!0}]}).setDrawer(function(t){i.paintLocationIndependentFrame(t,"#EEE","#EEE"),t.isInToolbox?i.paintGateSymbol(t,e+"=#\ndefault"):i.paintGateSymbol(t,e+"="+t.gate.param),i.paintGateButton(t)}).setOnClickGateFunc(function(t){var r=prompt("Enter new fallback value for input "+e+" (between 0 and 65535).",""+t.param);if(null===r||""===r.trim())return t;var n=parseInt(r);return!Number.isInteger(n)||n<0||n>=65536?(alert("'"+r+"' isn't an integer between 0 and 65535. Keeping "+t.param+"."),t):t.withParam(n)}).gate.withParam(2)};return o.InputAFamily=u("A",!1),o.InputBFamily=u("B",!1),o.InputRFamily=u("R",!1),o.InputRevAFamily=u("A",!0),o.InputRevBFamily=u("B",!0),o.SetA=s("A"),o.SetB=s("B"),o.SetR=s("R"),o.Letters=["A","B","R"],o.all=$traceurRuntime.spread(o.InputAFamily.all,o.InputBFamily.all,o.InputRFamily.all,o.InputRevAFamily.all,o.InputRevBFamily.all,[o.SetA,o.SetB,o.SetR]),{get InputGates(){return o}}}),$traceurRuntime.registerModule("src/gates/InterleaveBitsGates.js",[],function(){"use strict";function e(e,t){var r=Math.ceil(t/2);return 2*(e%r)+Math.floor(e/r)}function t(e,t){var r=Math.ceil(t/2);return Math.floor(e/2)+e%2*r}function r(e,t){for(var r=[],n=0;n<e;n++)r.push("r += mod(floor(out_id / "+(1<<t(n,e))+".0), 2.0) * "+(1<<n)+".0;");return u("","\n float r = 0.0;\n "+r.join("\n ")+"\n return r;\n ",e)}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/InterleaveBitsGates.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/InterleaveBitsGates.js")).Gate,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/InterleaveBitsGates.js")),o=a.ketArgs,u=a.ketShaderPermute,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/InterleaveBitsGates.js")).GatePainting,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/InterleaveBitsGates.js")).Point,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/gates/InterleaveBitsGates.js")).Seq,d={},m=l.range(n.MAX_SIMULATION_WIRE_COUNT+1).skip(2).toMap(function(e){return e},function(t){return r(t,e)}),f=l.range(n.MAX_SIMULATION_WIRE_COUNT+1).skip(2).toMap(function(e){return e},function(e){return r(e,t)}),h=function(t){return function(r){var i,a;if(void 0===r.positionInCircuit){s.paintBackground(r),s.paintOutline(r),s.paintResizeTab(r);for(var o=r.rect.x+6,u=r.rect.right()-6,l=r.rect.center().y-n.GATE_RADIUS+6,d=(2*(n.GATE_RADIUS-6)-14)/5,m=0;m<6;m++){var f=e(m,6),h=l+m*d+14*Math.floor(m/3),g=l+f*d+7*Math.floor(f/2),p=(i=(t?[g,h]:[h,g])[Symbol.iterator](),(a=i.next()).done?void 0:a.value),v=(a=i.next()).done?void 0:a.value;r.painter.strokePath([new c(o,p),new c(o+8,p),new c(u-8,v),new c(u,v)])}}else s.PERMUTATION_DRAWER(r)}};return d.InterleaveBitsGateFamily=i.buildFamily(4,16,function(t,r){return r.setSerializedId("weave"+t).setSymbol("Interleave").setTitle("Interleave").setBlurb("Re-orders blocks of bits into stripes of bits.").setWidth(t<=8?1:2).setDrawer(h(!1)).setActualEffectToShaderProvider(function(e){var r;return(r=m.get(t)).withArgs.apply(r,$traceurRuntime.spread(o(e,t)))}).setKnownEffectToBitPermutation(function(r){return e(r,t)})}),d.DeinterleaveBitsGateFamily=i.buildFamily(4,16,function(e,r){return r.setSerializedId("split"+e).setSymbol("Deinterleave").setTitle("Deinterleave").setBlurb("Re-orders stripes of bits into blocks of bits.").setWidth(e<=8?1:2).setDrawer(h(!0)).setActualEffectToShaderProvider(function(t){var r;return(r=f.get(e)).withArgs.apply(r,$traceurRuntime.spread(o(t,e)))}).setKnownEffectToBitPermutation(function(r){return t(r,e)})}),d.all=$traceurRuntime.spread(d.InterleaveBitsGateFamily.all,d.DeinterleaveBitsGateFamily.all),{get InterleaveBitsGates(){return d},get interleaveBit(){return e},get deinterleaveBit(){return t},get shaderFromBitPermutation(){return r}}}),$traceurRuntime.registerModule("src/gates/Joke_MysteryGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/gates/Joke_MysteryGate.js")).Complex,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Joke_MysteryGate.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Joke_MysteryGate.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/Joke_MysteryGate.js")).Matrix,i="?",a=function(e){return(new t).setSerializedIdAndSymbol(i).setTitle("Mystery Gate").setBlurb("Different every time.\n(Use shift+drag to copy circuit gates.)").setDrawer(r.MATRIX_SYMBOL_DRAWER_EXCEPT_IN_TOOLBOX).setKnownEffectToMatrix(e).gate},o=function(){return a(n.square(new e(Math.random()-.5,Math.random()-.5),new e(Math.random()-.5,Math.random()-.5),new e(Math.random()-.5,Math.random()-.5),new e(Math.random()-.5,Math.random()-.5)).closestUnitary(1e-5))};return{get MysteryGateSymbol(){return i},get MysteryGateMaker(){return o},get MysteryGateMakerWithMatrix(){return a}}}),$traceurRuntime.registerModule("src/gates/Joke_NeGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Joke_NeGate.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/Joke_NeGate.js")).Matrix,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/Joke_NeGate.js")).Point,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Joke_NeGate.js")).GatePainting,i=(new e).setSerializedId("NeGate").setTitle("Ne-Gate").setBlurb("Negates all amplitudes.").setDrawer(function(e){n.paintLocationIndependentFrame(e);var t=e.rect.center(),i=t.x,a=t.y;e.painter.strokeLine(new r(i-6,a),new r(i+6,a),"black",2)}).setKnownEffectToMatrix(t.square(-1,0,0,-1)).gate;return{get NeGate(){return i}}}),$traceurRuntime.registerModule("src/gates/Joke_ZeroGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/Joke_ZeroGate.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/Joke_ZeroGate.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/Joke_ZeroGate.js")).Matrix,n=(new e).setSerializedIdAndSymbol("0").setTitle("Zero Gate").setBlurb("Destroys the universe.").setDrawer(t.makeLocationIndependentGateDrawer("#666")).setKnownEffectToMatrix(r.square(0,0,0,0)).gate;return{get ZeroGate(){return n}}}),$traceurRuntime.registerModule("src/gates/MeasurementGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/MeasurementGate.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/MeasurementGate.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/MeasurementGate.js")).GatePainting,n=(new t).setSerializedIdAndSymbol("Measure").setTitle("Measurement Gate").setBlurb("Measures whether a qubit is ON or OFF, without conditioning on the result.").promiseHasNoNetEffectOnStateVector().setDrawer(function(t){var n,i,a,o,u=e.GATE_FILL_COLOR;t.isHighlighted&&(u=e.HIGHLIGHTED_GATE_FILL_COLOR),t.painter.fillRect(t.rect,u),r.paintOutline(t);var s=2*Math.PI,c=.4*t.rect.w,l=t.rect.center(),d=l.x,m=l.y;m+=.6*c;var f=-s/6,h=(n=[Math.cos(f)*c*1.5,Math.sin(f)*c*1.5][Symbol.iterator](),(i=n.next()).done?void 0:i.value),g=(i=n.next()).done?void 0:i.value,p=(a=[d+h,m+g][Symbol.iterator](),(o=a.next()).done?void 0:o.value),v=(o=a.next()).done?void 0:o.value;t.painter.trace(function(e){e.ctx.arc(d,m,c,s/2,s),e.line(d,m,p,v)}).thenStroke("black"),t.painter.trace(function(e){return e.arrowHead(p,v,.3*c,f,s/4)}).thenFill("black")}).setExtraDisableReasonFinder(function(e){if(e.isNested)return"can't\nnest\nmeasure\n(sorry)";var t=0!=(e.measuredMask&1<<e.outerRow);return e.innerColumn.hasControl()&&!t?"can't\ncontrol\n(sorry)":void 0}).gate;return{get MeasurementGate(){return n}}}),$traceurRuntime.registerModule("src/gates/ModularAdditionGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ModularAdditionGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ModularAdditionGates.js")),r=t.ketArgs,n=t.ketShaderPermute,i=t.ketInputGateShaderCode,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ModularAdditionGates.js")).Util,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ModularAdditionGates.js")).WglArg,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularIncrementGates.js","src/gates/ModularAdditionGates.js")).modulusTooBigChecker,s={},c=n("\n uniform float factor;\n "+i("A")+"\n "+i("R")+"\n ","\n float r = read_input_R();\n if (out_id >= r) {\n return out_id;\n }\n float d = read_input_A();\n d *= factor;\n d = mod(d, r);\n float result = mod(out_id + r - d, r);\n\n // Despite sanity, I consistently get result=33 instead of result=0 when out_id=0, d=0, r=33.\n // HACK: Fix it by hand.\n if (result >= r) {\n result -= r;\n }\n\n return result;\n ");return s.PlusAModRFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("+AmodR"+e).setSymbol("+A\nmod R").setTitle("Modular Addition Gate").setBlurb("Adds input A into the target, mod input R.\nOnly affects values below R.").setRequiredContextKeys("Input Range A","Input Range R").setExtraDisableReasonFinder(u("R",e)).setActualEffectToShaderProvider(function(t){var n;return(n=c).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["A","R"]),[o.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,r){return e<r?(e+t)%r:e})}),s.MinusAModRFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("-AmodR"+e).setSymbol("−A\nmod R").setTitle("Modular Subtraction Gate").setBlurb("Subtracts input A out of the target, mod input R.\nOnly affects values below R.").setRequiredContextKeys("Input Range A","Input Range R").setExtraDisableReasonFinder(u("R",e)).setActualEffectToShaderProvider(function(t){var n;return(n=c).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["A","R"]),[o.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,r){return e<r?a.properMod(e-t,r):e})}),s.all=$traceurRuntime.spread(s.PlusAModRFamily.all,s.MinusAModRFamily.all),{get ModularAdditionGates(){return s}}}),$traceurRuntime.registerModule("src/gates/ModularIncrementGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ModularIncrementGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ModularIncrementGates.js")),r=t.ketArgs,n=t.ketShaderPermute,i=t.ketInputGateShaderCode,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ModularIncrementGates.js")).Util,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ModularIncrementGates.js")).WglArg,u={},s=function(e,t){var r=void 0!==arguments[2]?arguments[2]:"mod";return function(n){var i=n.context.get("Input Range "+e),a=n.context.get("Input Default "+e);return void 0!==i&&i.length>t?r+"\ntoo\nbig":void 0===i&&void 0!==a&&a>1<<t?r+"\ntoo\nbig":void 0}},c=n("\n uniform float amount;\n "+i("R")+"\n ","\n float r = read_input_R();\n return out_id >= r\n ? out_id\n // HACK: sometimes mod(value-equal-to-r, r) returns r instead of 0. The perturbation works around it.\n : floor(mod(out_id + r - amount, r - 0.000001));");return u.IncrementModRFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("incmodR"+e).setSymbol("+1\nmod R").setTitle("Modular Increment Gate").setBlurb("Adds 1 into the target, but wraps R-1 to 0.\nOnly affects values less than R.").setRequiredContextKeys("Input Range R").setExtraDisableReasonFinder(s("R",e)).setActualEffectToShaderProvider(function(t){var n;return(n=c).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["R"]),[o.float("amount",1)]))}).setKnownEffectToParametrizedPermutation(function(e,t){return e<t?(e+1)%t:e})}),u.DecrementModRFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("decmodR"+e).setSymbol("−1\nmod R").setTitle("Modular Decrement Gate").setBlurb("Subtracts 1 out of the target, but wraps 0 to R-1.\nOnly affects values less than R.").setRequiredContextKeys("Input Range R").setExtraDisableReasonFinder(s("R",e)).setActualEffectToShaderProvider(function(t){var n;return(n=c).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["R"]),[o.float("amount",-1)]))}).setKnownEffectToParametrizedPermutation(function(e,t){return e<t?a.properMod(e-1,t):e})}),u.all=$traceurRuntime.spread(u.IncrementModRFamily.all,u.DecrementModRFamily.all),{get ModularIncrementGates(){return u},get modulusTooBigChecker(){return s}}}),$traceurRuntime.registerModule("src/gates/ModularMultiplicationGates.js",[],function(){"use strict";function e(e,t,r){return e>=r?e:0===(t=d.properMod(t,r))||1!==d.extended_gcd(t,r).gcd?e:e*t%r}function t(e,t,r){if(e>=r)return e;if(0===(t=d.properMod(t,r)))return e;var n=d.modular_multiplicative_inverse(t,r);return void 0===n?e:e*n%r}function r(e,t,r,n){if(e>=n)return e;t=d.properMod(t,n);var i=d.modular_multiplicative_inverse(t,n);if(void 0===i)return e;for(r<0&&(r=-r,t=i);r>0;)0!=(1&r)&&(e=e*t%n),t=t*t%n,r>>=1;return e}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/ModularMultiplicationGates.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ModularMultiplicationGates.js")).Gate,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ModularMultiplicationGates.js")),o=a.ketArgs,u=a.ketShaderPermute,s=a.ketInputGateShaderCode,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularIncrementGates.js","src/gates/ModularMultiplicationGates.js")).modulusTooBigChecker,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MultiplyAccumulateGates.js","src/gates/ModularMultiplicationGates.js")).BIG_MUL_MOD_SHADER_CODE,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ModularMultiplicationGates.js")).Util,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ModularMultiplicationGates.js")).WglArg,f={},h="\n vec2 _mod_mul_step(vec2 v, float q) {\n return vec2(v.y - q * v.x, v.x);\n }\n \n "+l+"\n\n float modular_multiplicative_inverse(float value, float modulus) {\n vec2 s = vec2(0.0, 1.0);\n vec2 t = vec2(1.0, 0.0);\n vec2 r = vec2(modulus, value);\n float q;\n // For values up to x, a number of iterations n satisfying phi^n > x should be sufficient.\n for (int repeat = 0; repeat < "+Math.ceil(n.MAX_SIMULATION_WIRE_COUNT/(Math.log2(1+Math.sqrt(5))-1))+"; repeat++) {\n if (r.x != 0.0) {\n q = floor(r.y / r.x);\n r = _mod_mul_step(r, q);\n s = _mod_mul_step(s, q);\n t = _mod_mul_step(t, q);\n }\n }\n if (r.y != 1.0) {\n return -1.0;\n }\n return mod(mod(s.y, modulus) + modulus, modulus);\n }\n",g="\n "+h+"\n\n float pow_mod(float base, float exponent, float modulus) {\n float base_inverse = modular_multiplicative_inverse(base, modulus);\n if (base_inverse == -1.0) {\n return -1.0;\n }\n\n if (exponent < 0.0) {\n base = base_inverse;\n exponent = -exponent;\n }\n\n float f = 1.0;\n for (int k = 0; k < "+n.MAX_SIMULATION_WIRE_COUNT+"; k++) {\n if (mod(exponent, 2.0) == 1.0) {\n exponent -= 1.0;\n f = big_mul_mod(f, base, modulus);\n }\n base = big_mul_mod(base, base, modulus);\n exponent /= 2.0;\n }\n return f;\n }\n",p=u("\n "+h+"\n "+s("A")+"\n "+s("R")+"\n ","\n float input_a = read_input_A();\n float modulus = read_input_R();\n input_a = mod(input_a, modulus);\n float v = modular_multiplicative_inverse(input_a, modulus);\n if (v == -1.0 || out_id >= modulus) {\n return out_id;\n }\n return big_mul_mod(out_id, v, modulus);\n "),v=u("\n "+h+"\n "+s("A")+"\n "+s("R")+"\n ","\n float input_a = read_input_A();\n float modulus = read_input_R();\n input_a = mod(input_a, modulus);\n if (modular_multiplicative_inverse(input_a, modulus) == -1.0 || out_id >= modulus) {\n return out_id;\n }\n return big_mul_mod(out_id, input_a, modulus);\n "),y=u("\n uniform float factor;\n "+s("A")+"\n "+s("B")+"\n "+s("R")+"\n "+g+"\n ","\n float exponent = -read_input_A() * factor;\n float base = read_input_B();\n float modulus = read_input_R();\n float f = pow_mod(base, exponent, modulus);\n if (f == -1.0 || out_id >= modulus) {\n return out_id;\n }\n return big_mul_mod(out_id, f, modulus);\n ");return f.TimesAModRFamily=i.buildFamily(1,16,function(t,r){return r.setSerializedId("*AmodR"+t).setSymbol("×A\nmod R").setTitle("Modular Multiplication Gate").setBlurb("Multiplies the target by input A mod input R.\nOnly affects values less than R.\nNo effect if the multiplication would be irreversible.").setRequiredContextKeys("Input Range A","Input Range R").setExtraDisableReasonFinder(c("R",t)).setActualEffectToShaderProvider(function(e){var r;return(r=p).withArgs.apply(r,$traceurRuntime.spread(o(e,t,["A","R"])))}).setKnownEffectToParametrizedPermutation(e)}),f.TimesAModRInverseFamily=i.buildFamily(1,16,function(e,r){return r.setSerializedId("/AmodR"+e).setSymbol("×A^-1\nmod R").setTitle("Modular Division Gate").setBlurb("Inverse-multiplies the target by input A mod input R.\nOnly affects values less than R.\nNo effect if the multiplication would be irreversible.").setRequiredContextKeys("Input Range A","Input Range R").setExtraDisableReasonFinder(c("R",e)).setActualEffectToShaderProvider(function(t){var r;return(r=v).withArgs.apply(r,$traceurRuntime.spread(o(t,e,["A","R"])))}).setKnownEffectToParametrizedPermutation(t)}),f.TimesBToTheAModRFamily=i.buildFamily(1,16,function(e,t){return t.setSerializedId("*BToAmodR"+e).setSymbol("×B^A\nmod R").setTitle("Modular Power Multiplication Gate").setBlurb("Multiplies the target by input B raised to the input A mod input R.\nOnly affects values less than R.\nNo effect if the multiplication would be irreversible.").setRequiredContextKeys("Input Range A","Input Range B","Input Range R").setExtraDisableReasonFinder(c("R",e)).setActualEffectToShaderProvider(function(t){var r;return(r=y).withArgs.apply(r,$traceurRuntime.spread(o(t,e,["A","B","R"]),[m.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,n,i){return r(e,n,t,i)})}),f.TimesInverseBToTheAModRFamily=i.buildFamily(1,16,function(e,t){return t.setSerializedId("/BToAmodR"+e).setSymbol("×B^-A\nmod R").setTitle("Modular Power Division Gate").setBlurb("Inverse-multiplies the target by input B raised to the input A mod input R.\nOnly affects values less than R.\nNo effect if the multiplication would be irreversible.").setRequiredContextKeys("Input Range A","Input Range B","Input Range R").setExtraDisableReasonFinder(c("R",e)).setActualEffectToShaderProvider(function(t){var r;return(r=y).withArgs.apply(r,$traceurRuntime.spread(o(t,e,["A","B","R"]),[m.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,n,i){return r(e,n,-t,i)})}),f.all=$traceurRuntime.spread(f.TimesAModRFamily.all,f.TimesAModRInverseFamily.all,f.TimesBToTheAModRFamily.all,f.TimesInverseBToTheAModRFamily.all),{get ModularMultiplicationGates(){return f},get MODULAR_INVERSE_SHADER_CODE(){return h},get POW_MOD_SHADER_CODE(){return g},get modularMultiply(){return e},get modularUnmultiply(){return t},get modularPowerMultiply(){return r}}}),$traceurRuntime.registerModule("src/gates/ModularMultiplyAccumulateGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MultiplyAccumulateGates.js","src/gates/ModularMultiplyAccumulateGates.js")).BIG_MUL_MOD_SHADER_CODE,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ModularMultiplyAccumulateGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ModularMultiplyAccumulateGates.js")),n=r.ketArgs,i=r.ketShaderPermute,a=r.ketInputGateShaderCode,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularIncrementGates.js","src/gates/ModularMultiplyAccumulateGates.js")).modulusTooBigChecker,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ModularMultiplyAccumulateGates.js")).Util,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ModularMultiplyAccumulateGates.js")).WglArg,c={},l=i("\n uniform float factor;\n "+a("A")+"\n "+a("B")+"\n "+a("R")+"\n "+e+"\n ","\n float r = read_input_R();\n float a = read_input_A();\n float b = read_input_B();\n\n float d = big_mul_mod(factor * a, b, r);\n\n float in_id = mod(out_id - d, r);\n if (in_id < 0.0) {\n in_id += r;\n }\n if (in_id >= r) {\n in_id -= r;\n }\n\n return out_id >= r ? out_id : in_id;\n ");return c.PlusABModRFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("+ABmodR"+e).setSymbol("+AB\nmod R").setTitle("Modular Multiply-Add Gate").setBlurb("Adds input A times input B into the target, mod input R.\nOnly affects values below R.").setRequiredContextKeys("Input Range A","Input Range B","Input Range R").setExtraDisableReasonFinder(o("R",e)).setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A","B","R"]),[s.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,r,n){return e<n?(e+t*r)%n:e})}),c.MinusABModRFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("-ABmodR"+e).setSymbol("−AB\nmod R").setTitle("Modular Multiply-Subtract Gate").setBlurb("Subtracts input A times input B out of the target, mod input R.\nOnly affects values below R.").setRequiredContextKeys("Input Range A","Input Range B","Input Range R").setExtraDisableReasonFinder(o("R",e)).setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A","B","R"]),[s.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(e,t,r,n){return e<n?u.properMod(e-t*r,n):e})}),c.all=$traceurRuntime.spread(c.PlusABModRFamily.all,c.MinusABModRFamily.all),{get ModularMultiplyAccumulateGates(){return c}}}),$traceurRuntime.registerModule("src/gates/MultiplicationGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/MultiplicationGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/MultiplicationGates.js")),r=t.ketArgs,n=t.ketShaderPermute,i=t.ketInputGateShaderCode,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularMultiplicationGates.js","src/gates/MultiplicationGates.js")),o=a.modularMultiply,u=a.modularUnmultiply,s=a.MODULAR_INVERSE_SHADER_CODE,c={},l=n("\n "+s+"\n "+i("A")+"\n ","\n float input_a = read_input_A();\n input_a = mod(input_a, span);\n float v = modular_multiplicative_inverse(input_a, span);\n if (v == -1.0) {\n return out_id;\n }\n return big_mul_mod(out_id, v, span);\n "),d=n("\n "+s+"\n "+i("A")+"\n ","\n float input_a = read_input_A();\n input_a = mod(input_a, span);\n if (modular_multiplicative_inverse(input_a, span) == -1.0) {\n return out_id;\n }\n return big_mul_mod(out_id, input_a, span);\n ");return c.TimesAFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("*A"+e).setSymbol("×A").setTitle("Multiplication Gate").setBlurb("Multiplies the target by input A.\nNo effect if the input is even (would be irreversible).").setRequiredContextKeys("Input Range A").setActualEffectToShaderProvider(function(t){var n;return(n=l).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["A"])))}).setKnownEffectToParametrizedPermutation(function(t,r){return o(t,r,1<<e)})}),c.TimesAInverseFamily=e.buildFamily(1,16,function(e,t){return t.setSerializedId("/A"+e).setSymbol("×A^-1").setTitle("Inverse Multiplication Gate").setBlurb("Inverse-multiplies the target by input A (modulo 2^n).\nNo effect if the input is even (would be irreversible).").setRequiredContextKeys("Input Range A").setKnownEffectToParametrizedPermutation(function(t,r){return u(t,r,1<<e)}).setActualEffectToShaderProvider(function(t){var n;return(n=d).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["A"])))})}),c.all=$traceurRuntime.spread(c.TimesAFamily.all,c.TimesAInverseFamily.all),{get MultiplicationGates(){return c},get MODULAR_INVERSE_SHADER_CODE(){return s}}}),$traceurRuntime.registerModule("src/gates/MultiplyAccumulateGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/MultiplyAccumulateGates.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/MultiplyAccumulateGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/MultiplyAccumulateGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/MultiplyAccumulateGates.js")),i=n.ketArgs,a=n.ketShaderPermute,o=n.ketInputGateShaderCode,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/MultiplyAccumulateGates.js")).WglArg,s={},c=function(e){var t=Math.ceil(e/2),r=Math.ceil((e-t)/2),n=Math.max(e-t-r,1);return[n,r,e-n-r]},l=function(e,t){return function(r){var n,i,a=(n=c(e)[Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=(i=n.next()).done?void 0:i.value,s=r&(1<<a)-1,l=r>>a&(1<<o)-1,d=r>>a+o;return d+=s*l*t,d&=(1<<u)-1,s|l<<a|d<<a+o}},d=6,m="\n // Avoids large multiplications that lose precision.\n float big_mul_mod(float b, float f, float modulus) {\n float t = 0.0;\n float r;\n for (int k = 0; k < "+Math.ceil(e.MAX_SIMULATION_WIRE_COUNT/d)+"; k++) {\n r = mod(f, "+(1<<d)+".0);\n f -= r;\n t = mod(t + b*r, modulus);\n b = mod(b * "+(1<<d)+".0, modulus);\n f /= "+(1<<d)+".0;\n }\n return t;\n }\n",f=a("\n uniform float factor;\n "+o("A")+"\n "+o("B")+"\n "+m+"\n ","\n float d1 = read_input_A();\n float d2 = read_input_B();\n float d = mod(big_mul_mod(d1, d2, span)*factor, span);\n return mod(out_id + span - d, span);");return s.Legacy_MultiplyAddFamily=t.buildFamily(3,16,function(e,t){return t.setSerializedId("c+=ab"+e).setSymbol("c+=ab").setTitle("Multiply-Add Gate").setBlurb("Adds the product of two numbers into a third.").setDrawer(r.SECTIONED_DRAWER_MAKER(["a","b","c+=ab"],c(e).slice(0,2).map(function(t){return t/e}))).setActualEffectToUpdateFunc(function(t){var r,n,i=(r=c(e)[Symbol.iterator](),(n=r.next()).done?void 0:n.value),a=(n=r.next()).done?void 0:n.value,o=(n=r.next()).done?void 0:n.value;return s.MultiplyAddInputsFamily.ofSize(o).customOperation(t.withRow(t.row+i+a).withInputSetToRange("A",t.row,i).withInputSetToRange("B",t.row+i,a))}).setKnownEffectToPermutation(l(e,1))}),s.Legacy_MultiplySubtractFamily=t.buildFamily(3,16,function(e,t){return t.setSerializedId("c-=ab"+e).setSymbol("c-=ab").setTitle("Multiply-Subtract Gate").setBlurb("Subtracts the product of two numbers from a third.").setDrawer(r.SECTIONED_DRAWER_MAKER(["a","b","c-=ab"],c(e).slice(0,2).map(function(t){return t/e}))).setActualEffectToUpdateFunc(function(t){var r,n,i=(r=c(e)[Symbol.iterator](),(n=r.next()).done?void 0:n.value),a=(n=r.next()).done?void 0:n.value,o=(n=r.next()).done?void 0:n.value;return s.MultiplySubtractInputsFamily.ofSize(o).customOperation(t.withRow(t.row+i+a).withInputSetToRange("A",t.row,i).withInputSetToRange("B",t.row+i,a))}).setKnownEffectToPermutation(l(e,-1))}),s.MultiplyAddInputsFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("+=AB"+e).setSymbol("+AB").setTitle("Multiply-Add Gate [Inputs A, B]").setBlurb("Adds the product of inputs A and B into the qubits covered by this gate.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(function(t){var r;return(r=f).withArgs.apply(r,$traceurRuntime.spread(i(t,e,["A","B"]),[u.float("factor",1)]))}).setKnownEffectToParametrizedPermutation(function(t,r,n){return t+r*n&(1<<e)-1})}),s.MultiplySubtractInputsFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("-=AB"+e).setSymbol("−AB").setTitle("Multiply-Subtract Gate [Inputs A, B]").setBlurb("Subtracts the product of inputs A and B out of the qubits covered by this gate.").setRequiredContextKeys("Input Range A","Input Range B").setActualEffectToShaderProvider(function(t){var r;return(r=f).withArgs.apply(r,$traceurRuntime.spread(i(t,e,["A","B"]),[u.float("factor",-1)]))}).setKnownEffectToParametrizedPermutation(function(t,r,n){return t-r*n&(1<<e)-1})}),s.SquareAddInputFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("+=AA"+e).setSymbol("+A^2").setTitle("Square-Add Gate [Input A]").setBlurb("Adds the square of input A into the qubits covered by this gate.").setRequiredContextKeys("Input Range A").setActualEffectToUpdateFunc(function(t){return s.MultiplyAddInputsFamily.ofSize(e).customOperation(t.withInputSetToOtherInput("B","A"))}).setKnownEffectToParametrizedPermutation(function(t,r){return t+r*r&(1<<e)-1})}),s.SquareSubtractInputFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("-=AA"+e).setSymbol("-A^2").setTitle("Square-Subtract Gate [Input A]").setBlurb("Subtracts the square of input A out of the qubits covered by this gate.").setRequiredContextKeys("Input Range A").setActualEffectToUpdateFunc(function(t){return s.MultiplySubtractInputsFamily.ofSize(e).customOperation(t.withInputSetToOtherInput("B","A"))}).setKnownEffectToParametrizedPermutation(function(t,r){return t-r*r&(1<<e)-1})}),s.all=$traceurRuntime.spread(s.Legacy_MultiplyAddFamily.all,s.Legacy_MultiplySubtractFamily.all,s.MultiplyAddInputsFamily.all,s.MultiplySubtractInputsFamily.all,s.SquareAddInputFamily.all,s.SquareSubtractInputFamily.all),{get MultiplyAccumulateGates(){return s},get BIG_MUL_MOD_SHADER_CODE(){return m},get MUL_STEP(){return d}}}),$traceurRuntime.registerModule("src/gates/ParametrizedRotationGates.js",[],function(){"use strict";function e(e){var t=e.getGateContext("Input Range A"),n=void 0===t?"ⁿ":c.digits_to_superscript_digits(""+t.length),i=e.gate.symbol.replace("ⁿ",n);r.paintBackground(e),r.paintOutline(e),r.paintGateSymbol(e,i)}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ParametrizedRotationGates.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/ParametrizedRotationGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ParametrizedRotationGates.js")),i=n.ketArgs,a=n.ketShader,o=n.ketShaderPhase,u=n.ketInputGateShaderCode,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/ParametrizedRotationGates.js")).WglArg,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ParametrizedRotationGates.js")).Util,l={},d=a("\n uniform float factor;\n "+u("A")+"\n ","\n float angle = read_input_A() * factor / _gen_input_span_A;\n float c = cos(angle) * 0.5;\n float s = sin(angle) * 0.5;\n vec2 u = vec2(0.5 + c, s);\n vec2 v = vec2(0.5 - c, -s);\n // multiply state by the matrix [[u, v], [v, u]]\n vec2 amp2 = inp(1.0-out_id);\n return cmul(u, amp) + cmul(v, amp2);\n "),m=a("\n uniform float factor;\n "+u("A")+"\n ","\n float angle = read_input_A() * factor / _gen_input_span_A;\n float c = cos(angle) * 0.5;\n float s = sin(angle) * 0.5;\n vec2 u = vec2(c + 0.5, s);\n vec2 v = vec2(s, 0.5 - c);\n // multiply state by the matrix [[u, v], [-v, u]]\n vec2 amp2 = inp(1.0-out_id);\n vec2 vs = v * (-1.0 + 2.0 * out_id);\n return cmul(u, amp) + cmul(vs, amp2);\n "),f=o("\n uniform float factor;\n "+u("A")+"\n ","\n return read_input_A() * out_id * factor / _gen_input_span_A;\n ");return l.XToA=(new t).setSerializedId("X^(A/2^n)").setSymbol("X^A/2ⁿ").setTitle("Parametrized X Gate").setBlurb("Rotates the target by input A / 2ⁿ'th of a half turn around the X axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=d).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",Math.PI)]))}).promiseEffectIsStable().promiseEffectIsUnitary().gate,l.XToMinusA=(new t).setSerializedId("X^(-A/2^n)").setSymbol("X^-A/2ⁿ").setTitle("Parametrized -X Gate").setBlurb("Counter-rotates the target by input A / 2ⁿ'th of a half turn around the X axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=d).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",-Math.PI)]))}).promiseEffectIsStable().promiseEffectIsUnitary().gate,l.YToA=(new t).setSerializedId("Y^(A/2^n)").setSymbol("Y^A/2ⁿ").setTitle("Parametrized Y Gate").setBlurb("Rotates the target by input A / 2ⁿ'th of a half turn around the Y axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=m).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",Math.PI)]))}).promiseEffectIsStable().promiseEffectIsUnitary().gate,l.YToMinusA=(new t).setSerializedId("Y^(-A/2^n)").setSymbol("Y^-A/2ⁿ").setTitle("Parametrized -Y Gate").setBlurb("Counter-rotates the target by input A / 2ⁿ'th of a half turn around the Y axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=m).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",-Math.PI)]))}).promiseEffectIsStable().promiseEffectIsUnitary().gate,l.ZToA=(new t).setSerializedId("Z^(A/2^n)").setSymbol("Z^A/2ⁿ").setTitle("Parametrized Z Gate").setBlurb("Rotates the target by input A / 2ⁿ'th of a half turn around the Z axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=f).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",Math.PI)]))}).promiseEffectIsStable().promiseEffectOnlyPhases().gate,l.ZToMinusA=(new t).setSerializedId("Z^(-A/2^n)").setSymbol("Z^-A/2ⁿ").setTitle("Parametrized -Z Gate").setBlurb("Counter-rotates the target by input A / 2ⁿ'th of a half turn around the Z axis.\nn is the number of qubits in input A.").setRequiredContextKeys("Input NO_DEFAULT Range A").setDrawer(e).setActualEffectToShaderProvider(function(e){var t;return(t=f).withArgs.apply(t,$traceurRuntime.spread(i(e,1,["A"]),[s.float("factor",-Math.PI)]))}).promiseEffectIsStable().promiseEffectOnlyPhases().gate,l.all=[l.XToA,l.XToMinusA,l.YToA,l.YToMinusA,l.ZToA,l.ZToMinusA],{get ParametrizedRotationGates(){return l}}}),$traceurRuntime.registerModule("src/gates/PhaseGradientGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/PhaseGradientGates.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/PhaseGradientGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/PhaseGradientGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/PhaseGradientGates.js")),i=n.ketArgs,a=n.ketShaderPhase,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/MultiplyAccumulateGates.js","src/gates/PhaseGradientGates.js")).MUL_STEP,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/gates/PhaseGradientGates.js")).WglArg,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/PhaseGradientGates.js")).Matrix,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/gates/PhaseGradientGates.js")).Complex,l=a("\n uniform float factor;\n\n /// Scales an angle by an integer factor.\n /// Performs the multiplication gradually, to avoid losing precision.\n float angle_mul(float base_angle, float whole_factor) {\n float result = 0.0;\n for (int k = 0; k < "+Math.ceil(e.MAX_SIMULATION_WIRE_COUNT/o)+"; k++) {\n result += base_angle * mod(whole_factor, "+(1<<o)+".0);\n result = mod(result, 6.283185307179586476925286766559);\n whole_factor = floor(whole_factor / "+(1<<o)+".0);\n base_angle = mod(base_angle * "+(1<<o)+".0, 6.283185307179586476925286766559);\n }\n return result;\n }\n ","\n return angle_mul(factor, out_id);\n "),d={};return d.PhaseGradientFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("PhaseGradient"+e).setSymbol("Grad^½").setTitle("Half Gradient Gate").setBlurb("Phases the target by an amount proportional its value.").setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(i(t,e),[u.float("factor",Math.PI/(1<<e))]))}).setKnownEffectToPhaser(function(t){return t/(2<<e)})}),d.PhaseDegradientFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("PhaseUngradient"+e).setSymbol("Grad^-½").setTitle("Inverse Half Gradient Gate").setBlurb("Counter-phases the target by an amount proportional its value.").setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(i(t,e),[u.float("factor",-Math.PI/(1<<e))]))}).setKnownEffectToPhaser(function(t){return-t/(2<<e)})}),d.DynamicPhaseGradientFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("grad^t"+e).setSymbol("Grad^t").setTitle("Cycling Gradient Gate").setBlurb("Phases the target by a cycling amount proportional its value.").setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(i(t,e),[u.float("factor",t.time*Math.PI*2)]))}).setEffectToTimeVaryingMatrix(function(t){return s.generateDiagonal(1<<e,function(e){return c.polar(1,2*t*Math.PI*e)})}).promiseEffectOnlyPhases().setDrawer(r.makeCycleDrawer(-1,-1,1,-Math.PI/2))}),d.DynamicPhaseDegradientFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("grad^-t"+e).setSymbol("Grad^-t").setTitle("Inverse Cycling Gradient Gate").setBlurb("Counter-phases the target by a cycling amount proportional its value.").setActualEffectToShaderProvider(function(t){var r;return(r=l).withArgs.apply(r,$traceurRuntime.spread(i(t,e),[u.float("factor",-t.time*Math.PI*2)]))}).setEffectToTimeVaryingMatrix(function(t){return s.generateDiagonal(1<<e,function(e){return c.polar(1,2*t*Math.PI*-e)})}).promiseEffectOnlyPhases().setDrawer(r.makeCycleDrawer(1,-1,1,Math.PI/2))}),d.all=$traceurRuntime.spread(d.PhaseGradientFamily.all,d.PhaseDegradientFamily.all,d.DynamicPhaseGradientFamily.all,d.DynamicPhaseDegradientFamily.all),{get PhaseGradientGates(){return d},get PHASE_GRADIENT_SHADER(){return l}}}),$traceurRuntime.registerModule("src/gates/PivotFlipGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/PivotFlipGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/PivotFlipGates.js")),r=t.ketArgs,n=t.ketShaderPermute,i=t.ketInputGateShaderCode,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ModularIncrementGates.js","src/gates/PivotFlipGates.js")).modulusTooBigChecker,o={},u=n("\n "+i("A")+"\n ","\n float a = read_input_A();\n return out_id >= a ? out_id : a - out_id - 1.0;\n ");return o.FlipUnderA=e.buildFamily(1,16,function(e,t){return t.setSerializedId("Flip<A"+e).setSymbol("Flip\n< A").setTitle("Pivot-Flip Gate").setBlurb("Reverses the order of states below the pivot value.").setRequiredContextKeys("Input Range A").setExtraDisableReasonFinder(a("A",e,"pivot")).setActualEffectToShaderProvider(function(t){var n;return(n=u).withArgs.apply(n,$traceurRuntime.spread(r(t,e,["A"])))}).setKnownEffectToParametrizedPermutation(function(e,t){return e>=t?e:t-e-1})}),o.all=$traceurRuntime.spread(o.FlipUnderA.all),{get PivotFlipGates(){return o}}}),$traceurRuntime.registerModule("src/gates/PostSelectionGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/gates/PostSelectionGates.js")).Complex,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/PostSelectionGates.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/PostSelectionGates.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/PostSelectionGates.js")).Matrix,i={},a=function(e){if(e.isInToolbox||e.isHighlighted?r.DEFAULT_DRAWER(e):(e.painter.fillRect(e.rect,"white"),r.paintGateSymbol(e)),!e.isInToolbox){var t=e.rect,n=t.x,i=t.y,a=t.w,o=t.h;e.painter.print("post-",n+a/2,i,"center","hanging","red","10px sans-serif",a,o/2),e.painter.print("select",n+a/2,i+o,"center","bottom","red","10px sans-serif",a,o/2)}};return i.PostSelectOff=(new t).setSerializedIdAndSymbol("|0⟩⟨0|").setTitle("Postselect Off").setBlurb("Keeps OFF states, discards/retries ON states.").setDrawer(a).setKnownEffectToMatrix(n.square(1,0,0,0)).gate,i.PostSelectOn=(new t).setSerializedIdAndSymbol("|1⟩⟨1|").setTitle("Postselect On").setBlurb("Keeps On states, discards/retries Off states.").setDrawer(a).setKnownEffectToMatrix(n.square(0,0,0,1)).gate,i.PostSelectAntiX=(new t).setSerializedId("|+⟩⟨+|").setSymbol("|⊖⟩⟨⊖|").setTitle("Postselect X-Off").setBlurb("Keeps ON+OFF states, discards/retries ON-OFF states.").setDrawer(a).setKnownEffectToMatrix(n.square(1,1,1,1).times(.5)).gate,i.PostSelectX=(new t).setSerializedId("|-⟩⟨-|").setSymbol("|⊕⟩⟨⊕|").setTitle("Postselect X-On").setBlurb("Keeps ON-OFF states, discards/retries ON+OFF states.").setDrawer(a).setKnownEffectToMatrix(n.square(1,-1,-1,1).times(.5)).gate,i.PostSelectAntiY=(new t).setSerializedId("|X⟩⟨X|").setSymbol("|⊘⟩⟨⊘|").setTitle("Postselect Y-Off").setBlurb("Keeps ON+iOFF states, discards ON-iOFF states.").setDrawer(a).setKnownEffectToMatrix(n.square(1,e.I.neg(),e.I,1).times(.5)).gate,i.PostSelectY=(new t).setSerializedId("|/⟩⟨/|").setSymbol("|⊗⟩⟨⊗|").setTitle("Postselect Y-On").setBlurb("Keeps ON-iOFF states, discards/retries ON+iOFF states.").setDrawer(a).setKnownEffectToMatrix(n.square(1,e.I,e.I.neg(),1).times(.5)).gate,i.all=[i.PostSelectOff,i.PostSelectOn,i.PostSelectAntiX,i.PostSelectX,i.PostSelectAntiY,i.PostSelectY],{get PostSelectionGates(){return i}}}),$traceurRuntime.registerModule("src/gates/PoweringGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/PoweringGates.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/PoweringGates.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/PoweringGates.js")).Matrix,n={},i=2*Math.PI,a=function(e){var t=Math.cos(i*e)/2,n=Math.sin(i*e)/2;return new r(2,2,new Float32Array([.5+t,n,.5-t,-n,.5-t,-n,.5+t,n]))},o=function(e){var t=Math.cos(i*e)/2,n=Math.sin(i*e)/2;return new r(2,2,new Float32Array([.5+t,n,-n,t-.5,n,.5-t,.5+t,n]))},u=function(e){var t=Math.cos(i*e),n=Math.sin(i*e);return new r(2,2,new Float32Array([1,0,0,0,0,0,t,n]))};return n.XForward=(new e).setSerializedIdAndSymbol("X^t").setTitle("X-Raising Gate (forward)").setBlurb("Right-handed cycle from no-op to X.").setDrawer(t.makeCycleDrawer(1,1)).setEffectToTimeVaryingMatrix(a).promiseEffectIsUnitary().gate,n.XBackward=(new e).setSerializedIdAndSymbol("X^-t").setTitle("X-Raising Gate (backward)").setBlurb("Left-handed cycle from no-op to X.").setDrawer(t.makeCycleDrawer(-1,1)).setEffectToTimeVaryingMatrix(function(e){return a(-e)}).promiseEffectIsUnitary().gate,n.YForward=(new e).setSerializedIdAndSymbol("Y^t").setTitle("Y-Raising Gate (forward)").setBlurb("Right-handed cycle from no-op to Y.").setDrawer(t.makeCycleDrawer(.5,1)).setEffectToTimeVaryingMatrix(o).promiseEffectIsUnitary().gate,n.YBackward=(new e).setSerializedIdAndSymbol("Y^-t").setTitle("Y-Raising Gate (backward)").setBlurb("Left-handed cycle from no-op to Y.").setDrawer(t.makeCycleDrawer(-.5,1)).setEffectToTimeVaryingMatrix(function(e){return o(-e)}).promiseEffectIsUnitary().gate,n.ZForward=(new e).setSerializedIdAndSymbol("Z^t").setTitle("Z-Raising Gate (forward)").setBlurb("Right-handed cycle from no-op to Z.").setDrawer(t.makeCycleDrawer(-1,-.5)).setEffectToTimeVaryingMatrix(u).promiseEffectOnlyPhases().gate,n.ZBackward=(new e).setSerializedIdAndSymbol("Z^-t").setTitle("Z-Raising Gate (backward)").setBlurb("Left-handed cycle from no-op to Z.").setDrawer(t.makeCycleDrawer(1,-.5)).setEffectToTimeVaryingMatrix(function(e){return u(-e)}).promiseEffectOnlyPhases().gate,n.all=[n.XForward,n.YForward,n.ZForward,n.XBackward,n.YBackward,n.ZBackward],{get PoweringGates(){return n}}}),$traceurRuntime.registerModule("src/gates/ProbabilityDisplay.js",[],function(){"use strict";function e(e,t,r,n){var i=new A(e);i.dontDeallocCurrentTexture();var a=x().vec2.arrayPowerSizeOfTexture(e);for(i.shadeAndTrade(function(e){return C(e,t)},T.takeVecFloatTex(a)),i.shadeAndTrade(function(e){return h.cycleAllBitsFloat(e,-r)});a>n;)a-=1,i.shadeHalveAndTrade(b.sumFoldFloat);return x().float.needRearrangingToBeInVec4Format&&i.shadeQuarterAndTrade(b.packFloatIntoVec4),i.currentTexture}function t(e,t){var r=1<<t,n=0,i=!0,a=!1,o=void 0;try{for(var u=void 0,s=e[Symbol.iterator]();!(i=(u=s.next()).done);i=!0)n+=u.value}catch(e){a=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(a)throw o}}if(isNaN(n)||n<1e-6)return p.zero(1,r).times(NaN);for(var c=new Float32Array(2*r),l=0;l<r;l++)c[2*l]=e[l]/n;return new p(1,r,c)}function r(e){var t=e,r=t.painter,n=t.rect,i=n.x,a=n.y,o=n.w,u=n.h,s=1<<e.gate.height,c=u/s;if(r.fillRect(e.rect,d.DISPLAY_GATE_BACK_COLOR),c<1)return e.painter.ctx.save(),e.painter.ctx.globalAlpha*=.2,r.fillRect(e.rect,"lightgray"),void e.painter.ctx.restore();var l=e.gate.height-5;r.trace(function(e){for(var t=1;t<s;t++)e.line(i,a+c*t,i+o,a+c*t)}).thenStroke("lightgray",l<=0?1:1/l),r.strokeRect(e.rect,"lightgray")}function n(e){var t=e,r=t.painter,n=t.rect,i=n.x,a=n.y,o=n.w,u=n.h,s=t.customStats,c=1<<e.gate.height,l=u/c,m=Math.max(l,1);r.ctx.save(),r.ctx.beginPath(),r.ctx.moveTo(i,a);for(var f=0;f<c;f++){var h=i+o*s.rawBuffer()[2*f],g=a+l*f;r.ctx.lineTo(h,g),r.ctx.lineTo(h,g+m)}r.ctx.lineTo(i,a+u),r.ctx.lineTo(i,a),r.ctx.strokeStyle="gray",r.ctx.lineWidth=1,r.ctx.stroke(),r.ctx.fillStyle=d.DISPLAY_GATE_FORE_COLOR,r.ctx.fill(),r.ctx.restore()}function i(e){var t=e,r=t.painter,n=t.rect,i=n.x,a=n.y,o=n.w,u=n.h,s=t.customStats,c=1<<e.gate.height,l=u/c,d=Math.max(l,1);r.ctx.save(),r.ctx.beginPath(),r.ctx.moveTo(i,a);for(var m=1/(4+Math.max(8,e.gate.height)),f=0;f<c;f++){var h=s.rawBuffer()[2*f],g=i+o*Math.min(1,Math.max(0,1+Math.log(h)*m)),p=a+l*f;r.ctx.lineTo(g,p),r.ctx.lineTo(g,p+d)}r.ctx.lineTo(i,a+u),r.ctx.lineWidth=1,r.ctx.strokeStyle="#CCC",r.ctx.stroke(),r.ctx.restore()}function a(e){var t=e,r=t.painter,n=t.rect,i=n.x,a=n.y,o=n.w,u=n.h,s=t.customStats,c=1<<e.gate.height,l=u/c,d=!0,m=!1,f=void 0;try{for(var h=void 0,p=e.focusPoints[Symbol.iterator]();!(d=(h=p.next()).done);d=!0){var v=h.value,b=Math.floor((v.y-a)/l);if(e.rect.containsPoint(v)&&b>=0&&b<c){var w=void 0===s?NaN:s.rawBuffer()[2*b];r.strokeRect(new y(i,a+b*l,o,l),"orange",2),g.paintDeferredValueTooltip(r,i+o,a+b*l,"Chance of |"+R.bin(b,e.gate.height)+"⟩ if measured","raw: "+(100*w).toFixed(4)+"%","log: "+(10*Math.log10(w)).toFixed(1)+" dB")}}}catch(e){m=!0,f=e}finally{try{d||null==p.return||p.return()}finally{if(m)throw f}}}function o(e){for(var t=e,r=t.painter,n=t.rect,i=n.x,a=n.y,o=n.w,u=n.h,s=t.customStats,c=u/s.height(),l=0;l<s.height();l++){var d=s.rawBuffer()[2*l];r.print((100*d).toFixed(1)+"%",i+o-2,a+c*(l+.5),"right","middle","black","8pt monospace",o-4,c)}}function u(e){r(e);var t=e.customStats;if(void 0===t||t.hasNaN())e.painter.printParagraph("NaN",e.rect,new v(.5,.5),"red");else{var u=e.rect.h/t.height()>8;u||i(e),n(e),u&&o(e)}a(e)}function s(e){return e.setSymbol("Chance").setTitle("Probability Display").setBlurb("Shows chances of outcomes if a measurement was performed.\nUse controls to see conditional probabilities.").promiseHasNoNetEffectOnStateVector().setExtraDisableReasonFinder(function(e){return e.isNested?"can't\nnest\ndisplays\n(sorry)":void 0})}function c(r,n){return s(n).setSerializedId("Chance"+r).setStatTexturesMaker(function(t){return e(t.stateTrader.currentTexture,t.controlsTexture,t.row,r)}).setStatPixelDataPostProcessor(function(e){return t(e,r)}).setDrawer(f.makeDisplayDrawer(u))}function l(e){return s(e).setSerializedId("Chance").markAsDrawerNeedsSingleQubitDensityStats().setDrawer(f.makeDisplayDrawer(function(e){var t=e.positionInCircuit,r=t.row,n=t.col;g.paintProbabilityBox(e.painter,e.stats.controlledWireProbabilityJustAfter(r,n),e.rect,e.focusPoints)}))}var d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/ProbabilityDisplay.js")).Config,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ProbabilityDisplay.js")).Gate,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/ProbabilityDisplay.js")).GatePainting,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateShaders.js","src/gates/ProbabilityDisplay.js")).GateShaders,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/gates/ProbabilityDisplay.js")).MathPainter,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/ProbabilityDisplay.js")).Matrix,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/ProbabilityDisplay.js")).Point,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/gates/ProbabilityDisplay.js")).Rect,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/Shaders.js","src/gates/ProbabilityDisplay.js")).Shaders,R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/ProbabilityDisplay.js")).Util,w=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/gates/ProbabilityDisplay.js")).WglConfiguredShader,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/gates/ProbabilityDisplay.js"))),M=w.Inputs,_=w.Outputs,x=w.currentShaderCoder,S=w.makePseudoShaderWithInputsAndOutputAndCode,T=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/gates/ProbabilityDisplay.js")).WglTexturePool,A=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTextureTrader.js","src/gates/ProbabilityDisplay.js")).WglTextureTrader,C=function(e,t){return $(e,t)},$=S([M.vec2("input"),M.bool("control")],_.float(),"float outputFor(float k) {\n vec2 amp = read_input(k);\n return dot(amp, amp) * read_control(k);\n }"),j=m.buildFamily(1,16,function(e,t){return 1===e?l(t):c(e,t)});return{get ProbabilityDisplayFamily(){return j},get probabilityStatTexture(){return e},get probabilityPixelsToColumnVector(){return t},get amplitudesToProbabilities(){return C}}}),$traceurRuntime.registerModule("src/gates/QuarterTurnGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/QuarterTurnGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/QuarterTurnGates.js")).Matrix,r={};return r.SqrtXForward=e.fromKnownMatrix("X^½",t.fromPauliRotation(.25,0,0),"√X Gate","Principle square root of Not."),r.SqrtXBackward=e.fromKnownMatrix("X^-½",t.fromPauliRotation(.75,0,0),"X^-½ Gate","Adjoint square root of Not."),r.SqrtYForward=e.fromKnownMatrix("Y^½",t.fromPauliRotation(0,.25,0),"√Y Gate","Principle square root of Y."),r.SqrtYBackward=e.fromKnownMatrix("Y^-½",t.fromPauliRotation(0,.75,0),"Y^-½ Gate","Adjoint square root of Y."),r.SqrtZForward=e.fromKnownMatrix("Z^½",t.fromPauliRotation(0,0,.25),"√Z Gate","Principle square root of Z.\nAlso known as the 'S' gate."),r.SqrtZBackward=e.fromKnownMatrix("Z^-½",t.fromPauliRotation(0,0,.75),"Z^-½ Gate","Adjoint square root of Z."),r.all=[r.SqrtXForward,r.SqrtYForward,r.SqrtZForward,r.SqrtXBackward,r.SqrtYBackward,r.SqrtZBackward],{get QuarterTurnGates(){return r}}}),$traceurRuntime.registerModule("src/gates/ReverseBitsGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/ReverseBitsGate.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/ReverseBitsGate.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/ReverseBitsGate.js")),n=r.ketArgs,i=r.ketShaderPermute,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/gates/ReverseBitsGate.js")).Seq.range(e.MAX_SIMULATION_WIRE_COUNT+1).map(function(e){return e<2?void 0:i("","\n float rev = 0.0;\n for (int k = 0; k < "+e+"; k++) {\n rev *= 2.0;\n rev += mod(out_id, 2.0);\n out_id = floor(out_id*0.5);\n }\n return rev;\n ",e)}).toArray(),o=function(e){return function(t){var r;return(r=a[e]).withArgs.apply(r,$traceurRuntime.spread(n(t,e)))}},u=t.buildFamily(2,16,function(e,t){return t.setSerializedId("rev"+e).setSymbol("Reverse").setTitle("Reverse Order").setBlurb("Swaps bits into the opposite order.").setKnownEffectToBitPermutation(function(t){return e-1-t}).setActualEffectToShaderProvider(o(e))});return{get ReverseBitsGateFamily(){return u},get reverseShaderForSize(){return o}}}),$traceurRuntime.registerModule("src/gates/SampleDisplay.js",[],function(){"use strict";function e(e){for(var t=e.customStats,r=t.rawBuffer(),n=e.painter.rng.random(),i=t.height(),a=0;;a++){var o=r[2*a];if(n-=o,a===i-1||n<1e-5)return{i:a,p:o}}}function t(t){for(var r=t,i=r.painter,a=r.rect,u=a.x,l=a.y,d=a.w,m=a.h,f=n.WIRE_SPACING,h=l+m/2-f*t.gate.height/2,g=e(t),p=g.i,v=g.p,y=0;y<t.gate.height;y++){var b=0!=(p>>y&1);b&&i.fillRect(new s(u,h+f*y+5,d,f-10),n.OPERATION_FORE_COLOR),i.print(b?"on":"off",u+d/2,h+f*(y+.5),"center","middle","black","16px sans-serif",d,f)}var R=!0,w=!1,M=void 0;try{for(var _=void 0,x=t.focusPoints[Symbol.iterator]();!(R=(_=x.next()).done);R=!0){var S=_.value,T=Math.floor(2*(S.y-l)/f)/2;t.rect.containsPoint(S)&&o.paintDeferredValueTooltip(i,u+d,l+T*f,"Sampled |"+c.bin(p,t.gate.height)+"⟩","decimal: |"+p+"⟩","chance: "+(100*v).toFixed(4)+"%",n.OPERATION_BACK_COLOR)}}catch(e){w=!0,M=e}finally{try{R||null==x.return||x.return()}finally{if(w)throw M}}}function r(e){e.painter.fillRect(e.rect,n.OPERATION_BACK_COLOR);var r=e.customStats;void 0===r||r.hasNaN()?e.painter.printParagraph("NaN",e.rect,new u(.5,.5),"red"):t(e),e.painter.strokeRect(e.rect,"lightgray")}var n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/SampleDisplay.js")).Config,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/SampleDisplay.js")).Gate,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/SampleDisplay.js")).GatePainting,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/gates/SampleDisplay.js")).MathPainter,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/gates/SampleDisplay.js")).Point,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/gates/SampleDisplay.js")).Rect,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/gates/SampleDisplay.js")).Util,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/ProbabilityDisplay.js","src/gates/SampleDisplay.js")),d=l.probabilityStatTexture,m=l.probabilityPixelsToColumnVector,f=i.buildFamily(1,16,function(e,t){return t.setSerializedId("Sample"+e).setSymbol("Sample").setTitle("Sampled Results Display").setBlurb("Shows a random sample of possible measurement outcomes.\nUse controls to see conditional samples.").setStatTexturesMaker(function(t){return d(t.stateTrader.currentTexture,t.controlsTexture,t.row,e)}).setStatPixelDataPostProcessor(function(t){return m(t,e)}).promiseHasNoNetEffectOnStateVectorButStillRequiresDynamicRedraw().setDrawer(a.makeDisplayDrawer(r)).setExtraDisableReasonFinder(function(e){return e.isNested?"can't\nnest\ndisplays\n(sorry)":void 0})});return{get SampleDisplayFamily(){return f}}}),$traceurRuntime.registerModule("src/gates/SpacerGate.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/SpacerGate.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/SpacerGate.js")).GateBuilder,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/SpacerGate.js")).GatePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/gates/SpacerGate.js")).Rect,i=(new t).setSerializedIdAndSymbol("…").setTitle("Spacer").setBlurb("A gate with no effect.").markAsNotInterestedInControls().promiseHasNoNetEffectOnStateVector().setDrawer(function(t){if(t.isInToolbox||t.isHighlighted){var i=e.GATE_FILL_COLOR;t.isHighlighted&&(i=e.HIGHLIGHTED_GATE_FILL_COLOR),t.painter.fillRect(t.rect,i),r.paintOutline(t)}else{var a=t.rect.center(),o=a.x,u=a.y,s=new n(o-14,u-2,28,4);t.painter.fillRect(s,e.BACKGROUND_COLOR_CIRCUIT)}t.painter.fillCircle(t.rect.center().offsetBy(7,0),2,"black"),t.painter.fillCircle(t.rect.center(),2,"black"),t.painter.fillCircle(t.rect.center().offsetBy(-7,0),2,"black")}).gate;return{get SpacerGate(){return i}}}),$traceurRuntime.registerModule("src/gates/SwapGateHalf.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/SwapGateHalf.js")).GateBuilder,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/gates/SwapGateHalf.js")).GatePainting,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/SwapGateHalf.js")).Matrix,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/gates/SwapGateHalf.js")).Rect,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/gates/SwapGateHalf.js")).Seq,a=(new e).setSerializedIdAndSymbol("Swap").setTitle("Swap Gate [Half]").setBlurb("Swaps the values of two qubits.\n(Place two in the same column.)").setKnownEffectToMatrix(r.square(1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1)).setDrawer(function(e){if(e.isInToolbox||e.isHighlighted)t.DEFAULT_DRAWER(e);else{var r=n.centeredSquareWithRadius(e.rect.center(),e.rect.w/6);e.painter.strokeLine(r.topLeft(),r.bottomRight()),e.painter.strokeLine(r.topRight(),r.bottomLeft())}}).setExtraDisableReasonFinder(function(e){var t=e.innerColumn,r=i.range(t.gates.length).filter(function(e){return t.gates[e]===a}),n=r.count();if(1===n)return"need\nother\nswap";if(n>2)return"too\nmany\nswap";var o=r.any(function(t){return 0!=(e.measuredMask&1<<t)}),u=r.any(function(t){return 0==(e.measuredMask&1<<t)});return o&&t.hasCoherentControl(e.measuredMask)?"no\nremix\n(sorry)":o&&u&&t.hasControl()?"no\nremix\n(sorry)":void 0}).gate;return{get SwapGateHalf(){return a}}}),$traceurRuntime.registerModule("src/gates/VariousXGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/VariousXGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/VariousXGates.js")).Matrix,r={};return r.X3=e.fromKnownMatrix("X^⅓",t.fromPauliRotation(1/6,0,0),"X^⅓ Gate","Principle third root of X."),r.X3i=e.fromKnownMatrix("X^-⅓",t.fromPauliRotation(-1/6,0,0),"X^-⅓ Gate","Adjoint third root of X."),r.X4=e.fromKnownMatrix("X^¼",t.fromPauliRotation(1/8,0,0),"X^¼ Gate","Principle fourth root of X."),r.X4i=e.fromKnownMatrix("X^-¼",t.fromPauliRotation(-1/8,0,0),"X^-¼ Gate","Adjoint fourth root of X."),r.X8=e.fromKnownMatrix("X^⅛",t.fromPauliRotation(1/16,0,0),"X^⅛ Gate","Principle eighth root of X."),r.X8i=e.fromKnownMatrix("X^-⅛",t.fromPauliRotation(-1/16,0,0),"X^-⅛ Gate","Adjoint eighth root of X."),r.X16=e.fromKnownMatrix("X^⅟₁₆",t.fromPauliRotation(1/32,0,0),"X^⅟₁₆ Gate","Principle sixteenth root of X."),r.X16i=e.fromKnownMatrix("X^-⅟₁₆",t.fromPauliRotation(-1/32,0,0),"X^-⅟₁₆ Gate","Adjoint sixteenth root of X."),r.X32=e.fromKnownMatrix("X^⅟₃₂",t.fromPauliRotation(1/64,0,0),"X^⅟₃₂ Gate","Principle 32'nd root of X."),r.X32i=e.fromKnownMatrix("X^-⅟₃₂",t.fromPauliRotation(-1/64,0,0),"X^-⅟₃₂ Gate","Adjoint 32'nd root of X."),r.all=[r.X3,r.X4,r.X8,r.X16,r.X32,r.X3i,r.X4i,r.X8i,r.X16i,r.X32i],{get VariousXGates(){return r}}}),$traceurRuntime.registerModule("src/gates/VariousYGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/VariousYGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/VariousYGates.js")).Matrix,r={};return r.Y3=e.fromKnownMatrix("Y^⅓",t.fromPauliRotation(0,1/6,0),"Y^⅓ Gate","Principle third root of Y."),r.Y3i=e.fromKnownMatrix("Y^-⅓",t.fromPauliRotation(0,-1/6,0),"Y^-⅓ Gate","Adjoint third root of Y."),r.Y4=e.fromKnownMatrix("Y^¼",t.fromPauliRotation(0,1/8,0),"Y^¼ Gate","Principle fourth root of Y."),r.Y4i=e.fromKnownMatrix("Y^-¼",t.fromPauliRotation(0,-1/8,0),"Y^-¼ Gate","Adjoint fourth root of Y."),r.Y8=e.fromKnownMatrix("Y^⅛",t.fromPauliRotation(0,1/16,0),"Y^⅛ Gate","Principle eighth root of Y."),r.Y8i=e.fromKnownMatrix("Y^-⅛",t.fromPauliRotation(0,-1/16,0),"Y^-⅛ Gate","Adjoint eighth root of Y."),r.Y16=e.fromKnownMatrix("Y^⅟₁₆",t.fromPauliRotation(0,1/32,0),"Y^⅟₁₆ Gate","Principle sixteenth root of Y."),r.Y16i=e.fromKnownMatrix("Y^-⅟₁₆",t.fromPauliRotation(0,-1/32,0),"Y^-⅟₁₆ Gate","Adjoint sixteenth root of Y."),r.Y32=e.fromKnownMatrix("Y^⅟₃₂",t.fromPauliRotation(0,1/64,0),"Y^⅟₃₂ Gate","Principle 32'nd root of Y."),r.Y32i=e.fromKnownMatrix("Y^-⅟₃₂",t.fromPauliRotation(0,-1/64,0),"Y^-⅟₃₂ Gate","Adjoint 32'nd root of Y."),r.all=[r.Y3,r.Y4,r.Y8,r.Y16,r.Y32,r.Y3i,r.Y4i,r.Y8i,r.Y16i,r.Y32i],{get VariousYGates(){return r}}}),$traceurRuntime.registerModule("src/gates/VariousZGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/VariousZGates.js")).Gate,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/gates/VariousZGates.js")).Matrix,r={};return r.Z3=e.fromKnownMatrix("Z^⅓",t.fromPauliRotation(0,0,1/6),"Z^⅓ Gate","Principle third root of Z."),r.Z3i=e.fromKnownMatrix("Z^-⅓",t.fromPauliRotation(0,0,-1/6),"Z^-⅓ Gate","Adjoint third root of Z."),r.Z4=e.fromKnownMatrix("Z^¼",t.fromPauliRotation(0,0,1/8),"Z^¼ Gate","Principle fourth root of Z.\nAlso known as the 'T' gate."),r.Z4i=e.fromKnownMatrix("Z^-¼",t.fromPauliRotation(0,0,-1/8),"Z^-¼ Gate","Adjoint fourth root of Z."),r.Z8=e.fromKnownMatrix("Z^⅛",t.fromPauliRotation(0,0,1/16),"Z^⅛ Gate","Principle eighth root of Z."),r.Z8i=e.fromKnownMatrix("Z^-⅛",t.fromPauliRotation(0,0,-1/16),"Z^-⅛ Gate","Adjoint eighth root of Z."),r.Z16=e.fromKnownMatrix("Z^⅟₁₆",t.fromPauliRotation(0,0,1/32),"Z^⅟₁₆ Gate","Principle 16'th root of Z."),r.Z16i=e.fromKnownMatrix("Z^-⅟₁₆",t.fromPauliRotation(0,0,-1/32),"Z^-⅟₁₆ Gate","Adjoint 16'th root of Z."),r.Z32=e.fromKnownMatrix("Z^⅟₃₂",t.fromPauliRotation(0,0,1/64),"Z^⅟₃₂ Gate","Principle 32'nd root of Z."),r.Z64=e.fromKnownMatrix("Z^⅟₆₄",t.fromPauliRotation(0,0,1/128),"Z^⅟₆₄ Gate","Principle 64'th root of Z."),r.Z128=e.fromKnownMatrix("Z^⅟₁₂₈",t.fromPauliRotation(0,0,1/256),"Z^⅟₁₂₈ Gate","Principle 128'th root of Z."),r.all=[r.Z3,r.Z4,r.Z8,r.Z16,r.Z32,r.Z64,r.Z128,r.Z3i,r.Z4i,r.Z8i,r.Z16i],{get VariousZGates(){return r}}}),$traceurRuntime.registerModule("src/gates/XorGates.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/gates/XorGates.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/gates/XorGates.js")).Gate,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/KetShaderUtil.js","src/gates/XorGates.js")),n=r.ketArgs,i={},a=(0,r.ketShaderPermute)((0,r.ketInputGateShaderCode)("A"),"\n float srcMask = mod(read_input_A(), span);\n float bitPos = 1.0;\n float result = 0.0;\n for (int i = 0; i < "+e.MAX_SIMULATION_WIRE_COUNT+"; i++) {\n float srcBit = mod(floor(srcMask/bitPos), 2.0);\n float dstBit = mod(floor(out_id/bitPos), 2.0);\n result += (dstBit + srcBit - dstBit * srcBit * 2.0) * bitPos;\n bitPos *= 2.0;\n }\n return result;");return i.XorAFamily=t.buildFamily(1,16,function(e,t){return t.setSerializedId("^=A"+e).setSymbol("⊕A").setTitle("Xor Gate [input A]").setBlurb("Xors input A into the qubits covered by this gate.").setRequiredContextKeys("Input Range A").setKnownEffectToParametrizedPermutation(function(t,r){return t^r&(1<<e)-1}).setActualEffectToShaderProvider(function(t){var r;return(r=a).withArgs.apply(r,$traceurRuntime.spread(n(t,e,["A"])))})}),i.all=$traceurRuntime.spread(i.XorAFamily.all),{get XorGates(){return i}}}),$traceurRuntime.registerModule("src/issues.js",[],function(){"use strict";function e(){return null===i||void 0===i}function t(){e()&&r("Can't simulate circuits. Your browser doesn't support WebGL, or has it disabled.","https://github.com/Strilanc/Quirk/issues/168",[/Computing circuit values failed/,/Error creating WebGL context./])}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/fallback.js","src/issues.js")).notifyAboutKnownIssue,n=document.createElement("canvas"),i=n.getContext("webgl")||n.getContext("experimental-webgl");return{get doDetectIssues(){return t},get canvasCreatedForTesting(){return n},get webglContextCreatedForTesting(){return i}}}),$traceurRuntime.registerModule("src/main.js",[],function(){"use strict";$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/Polyfills.js","src/main.js")),(0,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/fallback.js","src/main.js")).hookErrorHandler)(),(0,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/issues.js","src/main.js")).doDetectIssues)();var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/CooldownThrottle.js","src/main.js")).CooldownThrottle,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/main.js")).Config,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedInspector.js","src/main.js")).DisplayedInspector,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/main.js")).Painter,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/main.js")).Gates,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/main.js")).Rect,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/main.js")).Point,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/RestartableRng.js","src/main.js")).RestartableRng,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Revision.js","src/main.js")).Revision,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/main.js")),l=c.initSerializer,d=c.fromJsonText_CircuitDefinition,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/TouchScrollBlocker.js","src/main.js")).TouchScrollBlocker,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/main.js")).Util,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglContext.js","src/main.js")).initializedWglContext,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/MouseWatcher.js","src/main.js")),p=g.watchDrags,v=g.isMiddleClicking,y=g.eventPosRelativeTo,b=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/main.js")),R=b.ObservableValue,w=b.ObservableSource,M=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/exports.js","src/main.js")),_=M.initExports,x=M.obsExportsIsShowing,S=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/forge.js","src/main.js")),T=S.initForge,A=S.obsForgeIsShowing,C=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/menu.js","src/main.js")),$=C.initMenu,j=C.obsMenuIsShowing,E=C.closeMenu,I=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/undo.js","src/main.js")).initUndoRedo,G=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/clear.js","src/main.js")).initClear,P=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/url.js","src/main.js")).initUrlCircuitSync,k=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/title.js","src/main.js")).initTitleSync,N=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/sim.js","src/main.js")).simulate,O=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/main.js")).GatePainting,D=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedCircuit.js","src/main.js")).GATE_CIRCUIT_DRAWER;l(O.LABEL_DRAWER,O.MATRIX_DRAWER,D,O.LOCATION_INDEPENDENT_GATE_DRAWER);var z=document.getElementById("canvasDiv"),F=document.getElementById("drawCanvas");if(!F)throw new Error("Couldn't find 'drawCanvas'");F.width=z.clientWidth,F.height=.9*window.innerHeight;var B=!1,U=function(){var e,r={cur:new u};return(e=function(){r.cur=new u,setTimeout(e,.99*t.SEMI_STABLE_RANDOM_VALUE_LIFETIME_MILLIS)})(),r}(),L=document.getElementById("inspectorDiv"),W=new R(r.empty(new a(0,0,F.clientWidth,F.clientHeight))),H=s.startingAt(W.get().snapshot());H.latestActiveCommit().subscribe(function(e){var t=d(e),r=W.get().withCircuitDefinition(t);W.set(r)});var q=function(e){return{w:Math.max(z.clientWidth,e.desiredWidth()),h:e.desiredHeight()}},X=function(e){var t=q(e);return e.updateArea(new a(0,0,t.w,t.h)),e};W.observable().map(function(e){return e.displayedCircuit.circuitDefinition}).whenDifferent(f.CUSTOM_IS_EQUAL_TO_EQUALITY).subscribe(function(){var e=document.getElementById("error-div").style;e.opacity*=.9,e.opacity<.06&&(e.display="None")});var K,Y=new m(z),V=function(){if(B){var e=X(W.get()).previewDrop(),t=N(e.displayedCircuit.circuitDefinition),r=q(e);F.width=r.w,F.height=r.h;var i=new n(F,U.cur.restarted());e.updateArea(i.paintableArea()),e.paint(i,t),i.paintDeferred(),W.get().hand.paintCursor(i),Y.setBlockers(i.touchBlockers,i.desiredCursorStyle),F.style.cursor=i.desiredCursorStyle||"auto",W.get().stableDuration()<1/0&&window.requestAnimationFrame(function(){return K.trigger()})}};K=new e(V,t.REDRAW_COOLDOWN_MILLIS,.1,!0),window.addEventListener("resize",function(){return K.trigger()},!1),W.observable().subscribe(function(){return K.trigger()});var Z=void 0;z.addEventListener("click",function(e){var t=y(e,z),r=W.get();if(r.isHandOverButtonKey()===Z){var n=X(r.withHand(r.hand.withPos(t))).tryClick();void 0!==n&&H.commit(n.snapshot())}});var Q=new Set;z.addEventListener("keydown",function(e){Q.add(e.keyCode)}),z.addEventListener("keyup",function(e){Q.delete(e.keyCode)}),i.OtherZ.Z4.symbol="T",i.OtherZ.Z4i.symbol="T^-1",i.QuarterTurns.SqrtZForward.symbol="S",i.QuarterTurns.SqrtZBackward.symbol="S^-1",p(z,function(e,r){var n,a,u=W.get(),s=u.hand.withPos(e),c=X(u.withHand(s));if(void 0===(Z=c.isHandOverButtonKey())){var l=!1,d=!0,m=!1,f=void 0;try{for(var h=void 0,g=[["X",i.HalfTurns.X],["Y",i.HalfTurns.Y],["Z",i.HalfTurns.Z],["S",i.QuarterTurns.SqrtZForward],["T",i.OtherZ.Z4],["H",i.HalfTurns.H],["C",i.Controls.Control]][Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=(n=h.value[Symbol.iterator](),(a=n.next()).done?void 0:a.value),v=(a=n.next()).done?void 0:a.value;Q.has(p.charCodeAt(0))&&(s=c.hand.withHeldGate(v,new o(t.GATE_RADIUS,t.GATE_RADIUS)),c=c.withHand(s),l=!0)}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}l||(c=c.afterGrabbing(r.shiftKey,r.ctrlKey)),!W.get().isEqualTo(c)&&c.hand.isBusy()&&(H.startedWorkingOnCommit(),W.set(X(u.withHand(s).withJustEnoughWires(c.hand,1)).afterGrabbing(r.shiftKey,r.ctrlKey)),r.preventDefault())}else W.set(c)},function(e){H.cancelCommitBeingWorkedOn(),e.preventDefault()},function(e,t){if(W.get().hand.isBusy()){var r=W.get().hand.withPos(e),n=W.get().withHand(r);W.set(n),t.preventDefault()}},function(e,t){if(W.get().hand.isBusy()){var r=W.get().hand.withPos(e),n=X(W.get()).withHand(r).afterDropping().afterTidyingUp(),i=n.hand.withPos(void 0),a=n.withJustEnoughWires(i,0);H.commit(a.snapshot()),t.preventDefault()}}),z.addEventListener("mousedown",function(e){if(v(e)){var t=W.get().hand.withPos(y(e,F)),r=X(W.get()).withHand(t).afterGrabbing(!1,!1,!0).withHand(t).afterTidyingUp().withJustEnoughWires(t,0);W.get().isEqualTo(r)||(H.commit(r.snapshot()),e.preventDefault())}}),z.addEventListener("mousemove",function(e){if(!W.get().hand.isBusy()){var t=W.get().hand.withPos(y(e,F)),r=W.get().withHand(t);W.set(r)}}),z.addEventListener("mouseleave",function(){if(!W.get().hand.isBusy()){var e=W.get().hand.withPos(void 0),t=W.get().withHand(e);W.set(t)}});var J=new w;return P(H),_(H,J.observable()),T(H,J.observable()),I(H,J.observable()),G(H,J.observable()),$(H,J.observable()),k(H),A.zipLatest(x,function(e,t){return e||t}).zipLatest(j,function(e,t){return e||t}).whenDifferent().subscribe(function(e){J.send(e),z.tabIndex=e?-1:0}),B=!0,setTimeout(function(){L.style.display="block",V(),document.getElementById("loading-div").style.display="none",document.getElementById("close-menu-button").style.display="block",W.get().displayedCircuit.circuitDefinition.isEmpty()||E();try{h().onContextRestored=function(){return K.trigger()}}catch(e){console.error(e)}},0),{}}),$traceurRuntime.registerModule("src/math/Axis.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/math/Axis.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/math/Axis.js")).UNICODE_FRACTIONS,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/FormulaParser.js","src/math/Axis.js")).parseFormula,n=new Map,i=function(){function t(e,t,r){this.x=e,this.y=t,this.z=r}return $traceurRuntime.createClass(t,{toString:function(){return this.x+"X + "+this.y+"Y + "+this.z+"Z"},isEqualTo:function(e){return e instanceof t&&e.x===this.x&&e.y===this.y&&e.z===this.z}},{parse:function(i){var a=r(i,n);if(!(a instanceof t))throw new e("Not an axis.",{text:i,result:a});return a},classify:function(r){if("number"==typeof r)return!1;if(r instanceof t)return!0;throw new e("Not an axis or a number",{v:r})},op:function(e,r,n,i,a,o){var u=t.classify(e),s=t.classify(r);return u&&s?o(e,r):u||s?u?i(e,r):a(e,r):n(e,r)},times:function(r,n){return t.op(r,n,function(e,t){return e*t},function(e,r){return new t(e.x*r,e.y*r,e.z*r)},function(e,r){return new t(r.x*e,r.y*e,r.z*e)},function(t,r){throw new e("Can't multiply axes.",{a:t,b:r})})},add:function(r,n){return t.op(r,n,function(e,t){return e+t},function(t,r){throw new e("Can't add axes to numbers.",{a:t,b:r})},function(t,r){throw new e("Can't add axes to numbers.",{a:t,b:r})},function(e,r){return new t(e.x+r.x,e.y+r.y,e.z+r.z)})},negate:function(e){return t.classify(e)?new t(-e.x,-e.y,-e.z):-e},subtract:function(r,n){return t.op(r,n,function(e,t){return e-t},function(t,r){throw new e("Can't subtract axes and numbers.",{a:t,b:r})},function(t,r){throw new e("Can't subtract axes and numbers.",{a:t,b:r})},function(e,r){return new t(e.x-r.x,e.y-r.y,e.z-r.z)})},divide:function(r,n){return t.op(r,n,function(e,t){return e/t},function(e,r){return new t(e.x/r,e.y/r,e.z/r)},function(t,r){throw new e("Can't divide by an axis.",{a:t,b:r})},function(t,r){throw new e("Can't divide by an axis.",{a:t,b:r})})},raisedTo:function(r,n){return t.op(r,n,function(e,t){return Math.pow(e,t)},function(t,r){throw new e("Can't raise an axis to a power.",{a:t,b:r})},function(t,r){throw new e("Can't raise to an axis power.",{a:t,b:r})},function(t,r){throw new e("Can't raise to an axis power.",{a:t,b:r})})}})}();n.set("x",new i(1,0,0)),n.set("y",new i(0,1,0)),n.set("z",new i(0,0,1)),n.set("(","("),n.set(")",")");var a=!0,o=!1,u=void 0;try{for(var s=void 0,c=t[Symbol.iterator]();!(a=(s=c.next()).done);a=!0){var l=s.value,d=l.character,m=l.value;n.set(d,m)}}catch(e){o=!0,u=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw u}}return n.set("sqrt",{unary_action:function(e){return i.raisedTo(e,.5)},priority:4}),n.set("^",{binary_action:i.raisedTo,priority:3}),n.set("*",{binary_action:i.times,priority:2}),n.set("/",{binary_action:i.divide,priority:2}),n.set("-",{unary_action:i.negate,binary_action:i.subtract,priority:1}),n.set("+",{unary_action:function(e){return e},binary_action:i.add,priority:1}),n.set("√",n.get("sqrt")),{get Axis(){return i}}}),$traceurRuntime.registerModule("src/math/Complex.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/math/Complex.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/math/Complex.js")),r=t.Format,n=t.UNICODE_FRACTIONS,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/math/Complex.js")).Util,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/FormulaParser.js","src/math/Complex.js")).parseFormula,o=new Map,u=function(){function t(e,t){this.real=e,this.imag=t}return $traceurRuntime.createClass(t,{isEqualTo:function(e){return e instanceof t?this.real===e.real&&this.imag===e.imag:"number"==typeof e&&(this.real===e&&0===this.imag)},isApproximatelyEqualTo:function(e,r){if(e instanceof t||"number"==typeof e){var n=this.minus(t.from(e));return Math.abs(n.real)<=r&&Math.abs(n.imag)<=r&&n.abs()<=r}return!1},toString:function(e){return(e=e||r.EXACT).allowAbbreviation?this._toString_allowSingleValue(e):this._toString_bothValues(e)},_toString_allowSingleValue:function(e){return Math.abs(this.imag)<=e.maxAbbreviationError?e.formatFloat(this.real):Math.abs(this.real)<=e.maxAbbreviationError?Math.abs(this.imag-1)<=e.maxAbbreviationError?"i":Math.abs(this.imag+1)<=e.maxAbbreviationError?"-i":e.formatFloat(this.imag)+"i":this._toString_bothValues(e)},_toString_bothValues:function(e){var t=this.imag>=0?"+":"-",r=e.allowAbbreviation&&Math.abs(Math.abs(this.imag)-1)<=e.maxAbbreviationError?"":e.formatFloat(Math.abs(this.imag));return(e.allowAbbreviation||void 0===e.fixedDigits||this.real<0?"":"+")+e.formatFloat(this.real)+t+r+"i"},norm2:function(){return this.real*this.real+this.imag*this.imag},abs:function(){return Math.sqrt(this.norm2())},conjugate:function(){return new t(this.real,-this.imag)},neg:function(){return new t(-this.real,-this.imag)},phase:function(){return Math.atan2(this.imag,this.real)},unit:function(){var e=this.norm2();return e<1e-5?t.polar(1,this.phase()):this.dividedBy(Math.sqrt(e))},plus:function(e){var r=t.from(e);return new t(this.real+r.real,this.imag+r.imag)},minus:function(e){var r=t.from(e);return new t(this.real-r.real,this.imag-r.imag)},times:function(e){var r=t.from(e);return new t(this.real*r.real-this.imag*r.imag,this.real*r.imag+this.imag*r.real)},dividedBy:function(e){var r=t.from(e),n=r.norm2();if(0===n)throw new Error("Division by Zero");var i=this.times(r.conjugate());return new t(i.real/n,i.imag/n)},sqrts:function(){var e,r,n=(e=[this.real,this.imag][Symbol.iterator](),(r=e.next()).done?void 0:r.value),i=(r=e.next()).done?void 0:r.value,a=Math.sqrt(Math.sqrt(n*n+i*i));if(0===a)return[t.ZERO];if(0===i&&n<0)return[new t(0,a),new t(0,-a)];var o=this.phase()/2,u=t.polar(a,o);return[u,u.times(-1)]},exp:function(){return t.polar(Math.exp(this.real),this.imag)},ln:function(){return new t(Math.log(this.abs()),this.phase())},raisedTo:function(e){return.5===e&&0===this.imag&&this.real>=0?new t(Math.sqrt(this.real),0):t.ZERO.isEqualTo(e)?t.ONE:this.isEqualTo(t.ZERO)?t.ZERO:this.ln().times(t.from(e)).exp()}},{from:function(r){if(r instanceof t)return r;if("number"==typeof r)return new t(r,0);throw new e("Unrecognized value type.",{v:r})},polar:function(e,r){var n,a;return new t(e*(n=i.snappedCosSin(r)[Symbol.iterator](),(a=n.next()).done?void 0:a.value),e*((a=n.next()).done?void 0:a.value))},realPartOf:function(r){if(r instanceof t)return r.real;if("number"==typeof r)return r;throw new e("Unrecognized value type.",{v:r})},imagPartOf:function(r){if(r instanceof t)return r.imag;if("number"==typeof r)return 0;throw new e("Unrecognized value type.",{v:r})},parse:function(e){return t.from(a(e,o))},rootsOfQuadratic:function(e,r,n){if(e=t.from(e),r=t.from(r),n=t.from(n),e.isEqualTo(0)){if(!r.isEqualTo(0))return[n.times(-1).dividedBy(r)];if(!n.isEqualTo(0))return[];throw Error("Degenerate")}var i=r.times(r).minus(e.times(n).times(4)).sqrts(),a=r.times(-1),o=e.times(2);return i.map(function(e){return a.minus(e).dividedBy(o)})}})}();u.ZERO=new u(0,0),u.ONE=new u(1,0),u.I=new u(0,1),o.set("i",u.I),o.set("e",u.from(Math.E)),o.set("pi",u.from(Math.PI)),o.set("(","("),o.set(")",")");var s=!0,c=!1,l=void 0;try{for(var d=void 0,m=n[Symbol.iterator]();!(s=(d=m.next()).done);s=!0){var f=d.value,h=f.character,g=f.value;o.set(h,g)}}catch(e){c=!0,l=e}finally{try{s||null==m.return||m.return()}finally{if(c)throw l}}return o.set("sqrt",{unary_action:function(e){return u.from(e).raisedTo(.5)},priority:4}),o.set("exp",{unary_action:function(e){return u.from(e).exp()},priority:4}),o.set("ln",{unary_action:function(e){return u.from(e).ln()},priority:4}),o.set("cos",{unary_action:function(e){var t=u.from(e).times(new u(0,Math.PI/180));return t.exp().plus(t.neg().exp()).times(.5)},priority:4}),o.set("sin",{unary_action:function(e){var t=u.from(e).times(new u(0,Math.PI/180));return t.exp().minus(t.neg().exp()).dividedBy(new u(0,2))},priority:4}),o.set("asin",{unary_action:function(t){if(0!==u.imagPartOf(t))throw new e("asin input out of range",{e:t});return u.from(180*Math.asin(u.realPartOf(t))/Math.PI)},priority:4}),o.set("acos",{unary_action:function(t){if(0!==u.imagPartOf(t))throw new e("acos input out of range",{e:t});return u.from(180*Math.acos(u.realPartOf(t))/Math.PI)},priority:4}),o.set("^",{binary_action:function(e,t){return u.from(e).raisedTo(t)},priority:3}),o.set("*",{binary_action:function(e,t){return u.from(e).times(t)},priority:2}),o.set("/",{binary_action:function(e,t){return u.from(e).dividedBy(t)},priority:2}),o.set("-",{unary_action:function(e){return u.from(e).neg()},binary_action:function(e,t){return u.from(e).minus(t)},priority:1}),o.set("+",{unary_action:function(e){return e},binary_action:function(e,t){return u.from(e).plus(t)},priority:1}),o.set("√",o.get("sqrt")),o.set("arccos",o.get("acos")),o.set("arcsin",o.get("asin")),{get Complex(){return u}}}),$traceurRuntime.registerModule("src/math/FormulaParser.js",[],function(){"use strict";function e(e){for(var t=(e=$traceurRuntime.spread(e)).indexOf("e",1);-1!==t;t=e.indexOf("e",t+1)){var r=t-1,n=t+1;e[r].match(/[0-9]/)&&((e[n]+"").match(/[+-]/)&&(n+=1),(e[n]+"").match(/[0-9]/)&&(n+=1,e.splice(r,n-r,e.slice(r,n).join("")),t-=1))}return e}function t(t){return e(a(t.toLowerCase().split(/\s/)).flatMap(function(e){return a(e).segmentBy(function(e){return""===e.trim()?" ":e.match(/[\.0-9]/)?"#":e.match(/[_a-z]/)?"a":NaN}).map(function(e){return e.join("")})}).filter(function(e){return""!==e.trim()}).toArray())}function r(e,t){if(e.match(/[0-9]+(\.[0-9]+)?/))return parseFloat(e);if(t.has(e))return t.get(e);throw new i("Unrecognized token",{token:e})}function n(e,n){var a=t(e).map(function(e){return r(e,n)});a.length>0&&void 0!==a[a.length-1].priority&&(a=a.slice(0,a.length-1));var o=[],u=[],s=function(t){if("("===t)throw new i("Bad expression: unmatched '('",{text:e});if(u.length<2)throw new i("Bad expression: operated on nothing",{text:e});var r=u.pop(),n=u.pop();u.push(t.f(n,r))},c=function(e){for(;o.length>0&&u.length>=2&&void 0!==u[u.length-1];){var t=o[o.length-1];if(void 0===t.w||t.w<e)break;s(o.pop())}},l=!1,d=!0,m=!1,f=void 0;try{for(var h=void 0,g=a[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=h.value;!function(t,r){var a=n.get("*");if(t&&void 0===r.binary_action&&")"!==r&&(c(a.priority),o.push({f:a.binary_action,w:a.priority})),t&&void 0!==r.binary_action)c(r.priority),o.push({f:r.binary_action,w:r.priority});else if(void 0!==r.unary_action)c(r.priority),u.push(void 0),o.push({f:function(e,t){return r.unary_action(t)},w:1/0});else if(void 0!==r.binary_action)throw new i("Bad expression: binary op in bad spot",{text:e})}(l,p),l=function(e){return"("!==e&&void 0===e.priority}(p),"("===p?o.push("("):")"===p?function(){for(;;){if(0===o.length)throw new i("Bad expression: unmatched ')'",{text:e});var t=o.pop();if("("===t)break;s(t)}}():l&&u.push(p)}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}if(c(-1/0),1!==u.length||0!==o.length)throw new i("Incomplete expression",{text:e});return u[0]}var i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/math/FormulaParser.js")).DetailedError,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/math/FormulaParser.js")).seq;return{get parseFormula(){return n}}}),$traceurRuntime.registerModule("src/math/Matrix.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/math/Matrix.js")).Complex,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/math/Matrix.js")).DetailedError,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/math/Matrix.js")).Format,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/math/Matrix.js")),i=n.seq,a=n.Seq,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/math/Matrix.js")).Util,u=function(){function n(e,r,n){if(e*r*2!==n.length)throw new t("width*height*2 !== buffer.length",{width:e,height:r,len:n.length});this._width=e,this._height=r,this._buffer=n}return $traceurRuntime.createClass(n,{cell:function(r,n){if(r<0||n<0||r>=this._width||n>=this._height)throw new t("Cell out of range",{col:r,row:n,width:this._width,height:this._height});var i=2*(this._width*n+r);return new e(this._buffer[i],this._buffer[i+1])},rawBuffer:function(){return this._buffer},rows:function(){var e=this;return a.range(this._height).map(function(t){return a.range(e._width).map(function(r){return e.cell(r,t)}).toArray()}).toArray()},isEqualTo:function(e){var t=this;if(this===e)return!0;if(!(e instanceof n))return!1;var r=e;return this._width===r._width&&this._height===r._height&&a.range(this._buffer.length).every(function(e){return t._buffer[e]===r._buffer[e]})},isApproximatelyEqualTo:function(e,t){return e instanceof n&&this._width===e._width&&this._height===e._height&&Math.sqrt(this.minus(e).norm2())<=t},toString:function(){var e=void 0!==arguments[0]?arguments[0]:r.EXACT;return"{{"+this.rows().map(function(t){return t.map(function(t){return t.toString(e)}).join(e.itemSeparator)}).join("}"+e.itemSeparator+"{")+"}}"},width:function(){return this._width},height:function(){return this._height},isUnitary:function(e){var t=this.width();return this.height()===t&&this.times(this.adjoint()).isApproximatelyEqualTo(n.identity(t),e)},isLowerTriangular:function(){for(var e=void 0!==arguments[0]?arguments[0]:0,t=0;t<this._height;t++)for(var r=t+1;r<this._width;r++){var n=2*(t*this._width+r),i=this._buffer[n],a=this._buffer[n+1];if(isNaN(i)||isNaN(a)||i*i+a*a>e*e)return!1}return!0},isUpperTriangular:function(){for(var e=void 0!==arguments[0]?arguments[0]:0,t=0;t<this._height;t++)for(var r=0;r<t&&r<this._width;r++){var n=2*(t*this._width+r),i=this._buffer[n],a=this._buffer[n+1];if(isNaN(i)||isNaN(a)||i*i+a*a>e*e)return!1}return!0},isPhasedPermutation:function(){var e=void 0!==arguments[0]?arguments[0]:0;if(this._width!==this._height)return!1;for(var t=this._width,r=new Uint32Array(t),n=new Uint32Array(t),a=0;a<t;a++)for(var o=0;o<t;o++){var u=2*(o*t+a),s=Math.max(Math.abs(this._buffer[u]),Math.abs(this._buffer[u+1]));(isNaN(s)||s>e)&&(r[a]+=1,n[o]+=1)}return i(r).concat(n).every(function(e){return e<=1})},isApproximatelyHermitian:function(e){if(this._width!==this._height)return!1;for(var t=0;t<this._width;t++)for(var r=0;r<this._height;r++){var n=2*(this._width*r+t),i=2*(this._width*t+r);if(Math.abs(this._buffer[n]-this._buffer[i])>e)return!1;if(Math.abs(this._buffer[n+1]+this._buffer[i+1])>e)return!1}return!0},isIdentity:function(){var e=void 0!==arguments[0]?arguments[0]:0;if(this._width!==this._height)return!1;for(var t=0;t<this._width;t++)for(var r=0;r<this._height;r++){var n=2*(this._width*r+t),i=Math.abs(this._buffer[n]-(r===t?1:0)),a=Math.abs(this._buffer[n+1]);if(Math.max(i,a)>e)return!1}return!this.hasNaN()},isScaler:function(){var e=void 0!==arguments[0]?arguments[0]:0;if(this._width!==this._height)return!1;for(var t=this._buffer[0],r=this._buffer[1],n=0;n<this._width;n++)for(var i=0;i<this._height;i++){var a=2*(this._width*i+n),o=Math.abs(this._buffer[a]-(i===n?t:0)),u=Math.abs(this._buffer[a+1]-(i===n?r:0));if(Math.max(o,u)>e)return!1}return!this.hasNaN()},hasNaN:function(){for(var e=0;e<this._buffer.length;e++)if(isNaN(this._buffer[e]))return!0;return!1},isDiagonal:function(){for(var e=void 0!==arguments[0]?arguments[0]:0,t=0;t<this._width;t++)for(var r=0;r<this._height;r++)if(r!==t){var n=2*(this._width*r+t),i=Math.abs(this._buffer[n]),a=Math.abs(this._buffer[n+1]),o=Math.max(i,a);if(isNaN(o)||o>e)return!1}return this._width===this._height},adjoint:function(){for(var e=this._height,t=this._width,r=new Float64Array(e*t*2),i=0;i<t;i++)for(var a=0;a<e;a++){var o=2*(a*this._width+i),u=2*(i*e+a);r[u]=this._buffer[o],r[u+1]=-this._buffer[o+1]}return new n(e,t,r)},transpose:function(){for(var e=this._height,t=this._width,r=new Float64Array(e*t*2),i=0;i<t;i++)for(var a=0;a<e;a++){var o=2*(a*this._width+i),u=2*(i*e+a);r[u]=this._buffer[o],r[u+1]=this._buffer[o+1]}return new n(e,t,r)},trace:function(){for(var t=0,r=0,n=2*this._width+2,i=0;i<this._buffer.length;i+=n)t+=this._buffer[i],r+=this._buffer[i+1];return new e(t,r)},_timesScalar:function(t){for(var r=new Float64Array(this._buffer.length),i=e.realPartOf(t),a=e.imagPartOf(t),o=0;o<r.length;o+=2){var u=this._buffer[o],s=this._buffer[o+1];r[o]=u*i-s*a,r[o+1]=u*a+s*i}return new n(this._width,this._height,r)},plus:function(e){var t=this,r=t._width,i=t._height,a=t._buffer,u=e._buffer;o.need(e._width===r&&e._height===i,"Matrix.plus: compatible sizes");for(var s=new Float64Array(this._buffer.length),c=0;c<s.length;c++)s[c]=a[c]+u[c];return new n(r,i,s)},minus:function(e){var t=this,r=t._width,i=t._height,a=t._buffer,u=e._buffer;o.need(e._width===r&&e._height===i,"Matrix.minus: compatible sizes");for(var s=new Float64Array(this._buffer.length),c=0;c<s.length;c++)s[c]=a[c]-u[c];return new n(r,i,s)},_timesMatrix:function(e){if(this._width!==e._height)throw new t("Incompatible sizes.",{this:this,other:e});for(var r=e._width,i=this._height,a=this._width,o=new Float64Array(r*i*2),u=0;u<i;u++)for(var s=0;s<r;s++)for(var c=2*(u*r+s),l=0;l<a;l++){var d=2*(u*a+l),m=2*(l*r+s),f=this._buffer[d],h=this._buffer[d+1],g=e._buffer[m],p=e._buffer[m+1],v=f*g-h*p,y=f*p+g*h;o[c]+=v,o[c+1]+=y}return new n(r,i,o)},times:function(e){return e instanceof n?this._timesMatrix(e):this._timesScalar(e)},expandedForQubitInRegister:function(e,t,r){for(var i=Math.round(Math.log2(this._width)),a=n.identity(1<<t-e-i).tensorProduct(this).tensorProduct(n.identity(1<<e))._clone(),o=0;o<a._width;o++)for(var u=0;u<a._height;u++)if(!r.allowsState(o)||!r.allowsState(u)){var s=2*(o+u*a._width);a._buffer[s]=o===u?1:0,a._buffer[s+1]=0}return a},applyToStateVectorAtQubitWithControls:function(e,t,r){for(var i=2*this._width,a=e._buffer.slice(0,i),o=2<<t,u=o*i>>1,s=e._buffer.slice(),c=0;c<s.length;c+=u)for(var l=0;l<o;l+=2)if(r.allowsState((c|l)>>1)){for(var d=c+l,m=0;m<a.length;m+=2)a[m]=e._buffer[d],a[m+1]=e._buffer[d+1],d+=o;var f=this.times(new n(1,a.length>>1,a));d=c+l;for(var h=0;h<a.length;h+=2)s[d]=f._buffer[h],s[d+1]=f._buffer[h+1],d+=o}return new n(1,e.height(),s)},norm2:function(){var e=0,t=!0,r=!1,n=void 0;try{for(var i=void 0,a=this._buffer[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value;e+=o*o}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}return e},tensorProduct:function(e){for(var t=this._width,r=this._height,i=e._width,a=e._height,o=t*i,u=r*a,s=new Float64Array(o*u*2),c=0;c<r;c++)for(var l=0;l<a;l++)for(var d=0;d<t;d++)for(var m=0;m<i;m++){var f=2*(c*t+d),h=2*(l*i+m),g=2*((c*a+l)*o+(d*i+m)),p=this._buffer[f],v=this._buffer[f+1],y=e._buffer[h],b=e._buffer[h+1],R=p*y-v*b,w=p*b+v*y;s[g]=R,s[g+1]=w}return new n(o,u,s)},timesQubitOperation:function(e,t,r,i){var a,u;o.need(0==(r&1<<t),"Matrix.timesQubitOperation: self-controlled"),o.need(2===e._width&&2===e._height,"Matrix.timesQubitOperation: not 2x2");var s=this,c=s._width,l=s._height,d=s._buffer,m=(a=e._buffer[Symbol.iterator](),(u=a.next()).done?void 0:u.value),f=(u=a.next()).done?void 0:u.value,h=(u=a.next()).done?void 0:u.value,g=(u=a.next()).done?void 0:u.value,p=(u=a.next()).done?void 0:u.value,v=(u=a.next()).done?void 0:u.value,y=(u=a.next()).done?void 0:u.value,b=(u=a.next()).done?void 0:u.value;o.need(l>=2<<t,"Matrix.timesQubitOperation: qubit index out of range");for(var R=new Float64Array(d),w=0,M=0;M<l;M++)for(var _=0!=(r&M^i),x=0!=(M&1<<t),S=0;S<c;S++){if(!_&&!x){var T=w+2*(1<<t)*c,A=R[w],C=R[w+1],$=R[T],j=R[T+1];R[w]=A*m-C*f+$*h-j*g,R[w+1]=A*f+C*m+$*g+j*h,R[T]=A*p-C*v+$*y-j*b,R[T+1]=A*v+C*p+$*b+j*y}w+=2}return new n(c,l,R)},tensorPower:function(e){if(!Number.isInteger(e)||e<0)throw new t("Bad exponent",{exponent:e});for(var r=n.identity(1),i=this,a=1;a<=e;a*=2)0!=(a&e)&&(r=r.tensorProduct(i)),i=i.tensorProduct(i);return r},transformRealAndImagComponentsWith:function(e){for(var t=this._buffer.slice(),r=0;r<t.length;r++)t[r]=e(t[r]);return new n(this._width,this._height,t)},_inline_rowScale_preMultiply:function(e,t){for(var r=0;r<this._width;r++){var n=this.cell(r,e).times(t),i=2*(e*this._width+r);this._buffer[i]=n.real,this._buffer[i+1]=n.imag}},_inline_colScale_postMultiply:function(e,t){for(var r=0;r<this._height;r++){var n=this.cell(e,r).times(t),i=2*(r*this._width+e);this._buffer[i]=n.real,this._buffer[i+1]=n.imag}},_inline_rowMix_preMultiply:function(e,t,r){for(var n,i,a=(n=r._2x2Breakdown()[Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=(i=n.next()).done?void 0:i.value,s=(i=n.next()).done?void 0:i.value,c=0;c<this._width;c++){var l=this.cell(c,e),d=this.cell(c,t),m=l.times(a).plus(d.times(o)),f=l.times(u).plus(d.times(s)),h=2*(e*this._width+c),g=2*(t*this._width+c);this._buffer[h]=m.real,this._buffer[h+1]=m.imag,this._buffer[g]=f.real,this._buffer[g+1]=f.imag}},_inline_colMix_postMultiply:function(e,t,r){for(var n,i,a=(n=r._2x2Breakdown()[Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=(i=n.next()).done?void 0:i.value,s=(i=n.next()).done?void 0:i.value,c=0;c<this._width;c++){var l=this.cell(e,c),d=this.cell(t,c),m=l.times(a).plus(d.times(u)),f=l.times(o).plus(d.times(s)),h=2*(c*this._width+e),g=2*(c*this._width+t);this._buffer[h]=m.real,this._buffer[h+1]=m.imag,this._buffer[g]=f.real,this._buffer[g+1]=f.imag}},_clone:function(){return new n(this._width,this._height,this._buffer.slice())},qrDecomposition:function(){if(this._width!==this._height)throw new t("Expected a square matrix.",this);for(var e=n.identity(this._width),r=this._clone(),i=0;i<this._height;i++){for(var a=0;a<i&&a<this._width;a++){var o=r.cell(a,i),u=r.cell(a,a),s=u.abs(),c=o.abs();if(0!==c){var l=-Math.atan2(c,s),d=Math.cos(l),m=Math.sin(l),f=u.unit().conjugate(),h=o.unit().conjugate(),g=n.square(f.times(d),h.times(-m),f.times(m),h.times(d));r._inline_rowMix_preMultiply(a,i,g),e._inline_colMix_postMultiply(a,i,g.adjoint())}}var p=r.cell(i,i).unit();r._inline_rowScale_preMultiply(i,p.conjugate()),e._inline_colScale_postMultiply(i,p)}return{Q:e,R:r}},lqDecomposition:function(){var e=this.adjoint().qrDecomposition(),t=e.Q;return{L:e.R.adjoint(),Q:t.adjoint()}},eigenvalueMagnitudes:function(e){var r=void 0!==arguments[1]?arguments[1]:1e3;if(this._width!==this._height)throw new t("Expected a square matrix.",this);for(var n=0,i=this;!i.isUpperTriangular(e)&&n<r;){var o=i.qrDecomposition(),u=o.Q,s=o.R;if(s.isIdentity(e))return a.repeat(1,this._width).toArray();i=s.times(u),n++}return a.range(this._width).map(function(e){return i.cell(e,e).abs()}).sortedBy(function(e){return-e}).toArray()},eigenDecomposition:function(){var t,r;if(2!==this.width()||2!==this.height())throw new Error("Not implemented: non-2x2 eigen decomposition");var i=(t=this._2x2Breakdown()[Symbol.iterator](),(r=t.next()).done?void 0:r.value),a=(r=t.next()).done?void 0:r.value,o=(r=t.next()).done?void 0:r.value,u=(r=t.next()).done?void 0:r.value,s=e.rootsOfQuadratic(e.ONE,i.plus(u).times(-1),i.times(u).minus(a.times(o)));if(0===s.length)throw new Error("Degenerate");return 1===s.length?[{val:s[0],vec:n.col(1,0)},{val:s[0],vec:n.col(0,1)}]:s.map(function(t){var r,s,c,l,d=(r=[a.times(-1),i.minus(t)][Symbol.iterator](),(s=r.next()).done?void 0:s.value),m=(s=r.next()).done?void 0:s.value;d.isEqualTo(0)&&m.isEqualTo(0)&&(d=(l=(c=[t.minus(u),o][Symbol.iterator]()).next()).done?void 0:l.value,m=(l=c.next()).done?void 0:l.value),d.isEqualTo(0)||(m=m.dividedBy(d),d=e.ONE);var f=Math.sqrt(d.norm2()+m.norm2());if(0===f)throw new Error("Unexpected degenerate");return{val:t,vec:n.col(d,m).times(1/f)}})},liftApply:function(e){var t=this.times(0),r=!0,n=!1,i=void 0;try{for(var a=void 0,o=this.eigenDecomposition()[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value,s=u.val,c=u.vec,l=e(s),d=c.times(c.adjoint());t=t.plus(d.times(l))}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return t},qubitDensityMatrixToBlochVector:function(){var e,r;if(2!==this._width||2!==this._height)throw new t("Need a 2x2 density matrix.",this);if(!this.isApproximatelyHermitian(.01))throw new t("Density matrix should be Hermitian.",this);if(!this.trace().isApproximatelyEqualTo(1,.01))throw new t("Density matrix should have unit trace.",this);var n=(e=this._buffer[Symbol.iterator](),(r=e.next()).done?void 0:r.value),i=((r=e.next()).done||r.value,(r=e.next()).done?void 0:r.value),a=(r=e.next()).done?void 0:r.value,o=(r=e.next()).done?void 0:r.value,u=(r=e.next()).done?void 0:r.value,s=(r=e.next()).done?void 0:r.value;(r=e.next()).done||r.value;return[-o-i,a-u,s-n]},determinant:function(){var t=this;o.need(this.width()===this.height(),"Must be square");var r=this.width();return 1===r?this.cell(0,0):a.range(r).map(function(e){return n.generate(r-1,r-1,function(r,n){return t.cell(n+(n<e?0:1),r+1)}).determinant().times(t.cell(e,0)).times(Math.pow(-1,e))}).aggregate(e.ZERO,function(e,t){return e.plus(t)})},_2x2Breakdown:function(){return[new e(this._buffer[0],this._buffer[1]),new e(this._buffer[2],this._buffer[3]),new e(this._buffer[4],this._buffer[5]),new e(this._buffer[6],this._buffer[7])]},qubitOperationToAngleAxisRotation:function(){var t,r;o.need(2===this.width()&&2===this.height(),"Need a 2x2 matrix."),o.need(this.isUnitary(.01),"Need a unitary matrix.");var n=(t=this._2x2Breakdown()[Symbol.iterator](),(r=t.next()).done?void 0:r.value),a=(r=t.next()).done?void 0:r.value,u=(r=t.next()).done?void 0:r.value,s=(r=t.next()).done?void 0:r.value,c=n.plus(s),l=a.plus(u).dividedBy(e.I),d=a.minus(u),m=n.minus(s).dividedBy(e.I),f=i([c,l,d,m]).maxBy(function(e){return e.abs()}).unit().times(2),h=Math.min(1,Math.max(-1,c.dividedBy(f).real)),g=l.dividedBy(f).real,p=d.dividedBy(f).real,v=m.dividedBy(f).real,y=-2*Math.acos(h),b=Math.sqrt(g*g+p*p+v*v);return b<1e-7?{axis:[1,0,0],angle:0,phase:f.phase()}:(g/=b,p/=b,v/=b,y<=-Math.PI&&(y+=2*Math.PI,f=f.times(-1)),g+p+v<0&&(g=-g,p=-p,v=-v,y=-y),{axis:[g,p,v],angle:y,phase:f.phase()})},cross3:function(e){var t=this;return o.need(1===this.width()&&3===this.height(),"This isn't a 3d column vector."),o.need(1===e.width()&&3===e.height(),"Other's not a 3d column vector."),n.generate(1,3,function(r){var n,i,a=(n=[(r+1)%3,(r+2)%3][Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=t.cell(0,a).times(e.cell(0,o)),s=t.cell(0,o).times(e.cell(0,a));return u.minus(s)})},_unordered_singularValueDecomposition_2x2:function(){var e,t,r=n.identity(2),i=this.lqDecomposition(),a=i.L,o=i.Q,u=a.cell(0,0).unit(),s=a.cell(0,1).unit();r._inline_colScale_postMultiply(0,u),r._inline_colScale_postMultiply(1,s),a._inline_rowScale_preMultiply(0,u.conjugate()),a._inline_rowScale_preMultiply(1,s.conjugate());var c=a.cell(1,1).unit();a._inline_colScale_postMultiply(1,c.conjugate()),o._inline_rowScale_preMultiply(1,c);var l=(e=a._buffer[Symbol.iterator](),(t=e.next()).done?void 0:t.value),d=(e.next(),(t=e.next()).done?void 0:t.value),m=(e.next(),(t=e.next()).done?void 0:t.value),f=(e.next(),(t=e.next()).done?void 0:t.value),h=l+f,g=d+m,p=d-m,v=l-f,y=Math.atan2(g,h)/2,b=Math.atan2(p,v)/2,R=Math.sqrt(h*h+g*g)/2,w=Math.sqrt(v*v+p*p)/2;return r._inline_colMix_postMultiply(0,1,n.rotation(y-b)),o._inline_rowMix_preMultiply(0,1,n.rotation(y+b)),a=n.square(R+w,0,0,R-w),{U:r,S:a,V:o}},_unordered_singularValueDecomposition_iterative:function(){for(var e=void 0!==arguments[0]?arguments[0]:0,t=void 0!==arguments[1]?arguments[1]:100,r=n.identity(this._width),i=this._clone(),a=n.identity(this._width),o=0;!i.isDiagonal(e)&&o++<t;){var u=i.qrDecomposition(),s=u.Q,c=u.R.lqDecomposition(),l=c.L,d=c.Q;r=r.times(s),i=l,a=d.times(a)}return{U:r,S:i,V:a}},singularValueDecomposition:function(){var e,r,i,o,u,s,c,l,d,m=void 0!==arguments[0]?arguments[0]:0,f=void 0!==arguments[1]?arguments[1]:100;if(this._width!==this._height)throw new t("Expected a square matrix.",this);for(var h=2===this._width?this._unordered_singularValueDecomposition_2x2():this._unordered_singularValueDecomposition_iterative(m,f),g=h.U,p=h.S,v=h.V,y=a.range(this._width).sortedBy(function(e){return-p.cell(e,e).norm2()}).toArray(),b=0;b<p._width;b++){var R=y[b];b!==R&&(g._inline_colMix_postMultiply(b,R,n.PAULI_X),v._inline_rowMix_preMultiply(b,R,n.PAULI_X),e=[p._buffer[2*R],p._buffer[2*b]],p._buffer[2*b]=(r=e[Symbol.iterator](),(i=r.next()).done?void 0:i.value),p._buffer[2*R]=(i=r.next()).done?void 0:i.value,o=[p._buffer[2*R+1],p._buffer[2*b+1]],p._buffer[2*b+1]=(u=o[Symbol.iterator](),(s=u.next()).done?void 0:s.value),p._buffer[2*R+1]=(s=u.next()).done?void 0:s.value,c=[y[b],y[R]],y[R]=(l=c[Symbol.iterator](),(d=l.next()).done?void 0:d.value),y[b]=(d=l.next()).done?void 0:d.value)}for(var w=0;w<p._width;w++)g._inline_colScale_postMultiply(w,p.cell(w,w).unit());return p=n.generateDiagonal(p._width,function(e){return p.cell(e,e).abs()}),{U:g,S:p,V:v}},getColumn:function(e){o.need(e>=0&&e<=this.width(),"colIndex >= 0 && colIndex <= this.width()");for(var t=[],r=0;r<this._height;r++)t.push(this.cell(e,r));return t},getRow:function(e){o.need(e>=0&&e<=this.height(),"rowIndex >= 0 && rowIndex <= this.height()");for(var t=[],r=0;r<this._width;r++)t.push(this.cell(r,e));return t},closestUnitary:function(){var e=void 0!==arguments[0]?arguments[0]:0,t=void 0!==arguments[1]?arguments[1]:100,r=this.singularValueDecomposition(e,t);return r.U.times(r.V)}},{fromRows:function(r){o.need(Array.isArray(r)&&r.every(Array.isArray),"array rows",r),o.need(r.length>0,"non-zero height",arguments);var a=i(r),u=r.length,s=a.map(function(e){return e.length}).distinct().single(null);if(null===s)throw new t("Inconsistent row widths.",{rows:r});var c=new Float64Array(s*u*2),l=0,d=!0,m=!1,f=void 0;try{for(var h=void 0,g=r[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var p=h.value,v=!0,y=!1,b=void 0;try{for(var R=void 0,w=p[Symbol.iterator]();!(v=(R=w.next()).done);v=!0){var M=R.value;c[l]=e.realPartOf(M),c[l+1]=e.imagPartOf(M),l+=2}}catch(e){y=!0,b=e}finally{try{v||null==w.return||w.return()}finally{if(y)throw b}}}}catch(e){m=!0,f=e}finally{try{d||null==g.return||g.return()}finally{if(m)throw f}}return new n(s,u,c)},parse:function(t){if((t=t.replace(/\s/g,"")).length<4||"{{"!==t.substr(0,2)||"}}"!==t.substr(t.length-2,2))throw new Error("Not surrounded by {{}}.");return n.fromRows(t.substr(2,t.length-4).split("},{").map(function(t){return t.split(",").map(e.parse)}))},generate:function(t,r,i){for(var a=new Float64Array(t*r*2),o=0;o<r;o++)for(var u=0;u<t;u++){var s=2*(o*t+u),c=i(o,u);a[s]=e.realPartOf(c),a[s+1]=e.imagPartOf(c)}return new n(t,r,a)},generateDiagonal:function(t,r){for(var i=new Float64Array(t*t*2),a=0;a<t;a++){var o=a*(t+1)*2,u=r(a);i[o]=e.realPartOf(u),i[o+1]=e.imagPartOf(u)}return new n(t,t,i)},generateTransition:function(e,t){for(var r=new Float64Array(e*e*2),i=0;i<e;i++)r[2*(t(i)*e+i)]=1;return new n(e,e,r)},zero:function(e,t){return new n(e,t,new Float64Array(e*t*2))},solo:function(t){return new n(1,1,new Float64Array([e.realPartOf(t),e.imagPartOf(t)]))},square:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.need(Array.isArray(e),"Array.isArray(coefs)",arguments);var r=Math.round(Math.sqrt(e.length));return o.need(r*r===e.length,"Matrix.square: non-square number of arguments"),n.generate(r,r,function(t,n){return e[t*r+n]})},col:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o.need(Array.isArray(e),"Array.isArray(coefs)",arguments),n.generate(1,e.length,function(t){return e[t]})},row:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o.need(Array.isArray(e),"Array.isArray(coefs)",arguments),n.generate(e.length,1,function(t,r){return e[r]})},fromPauliRotation:function(t,i,a){var u,s,c=function(e){return Math.abs(e)<2e-4?1-e*e/6:Math.sin(e)/e},l=-11*(t=-t*Math.PI*2)+-13*(i=-i*Math.PI*2)+-17*(a=-a*Math.PI*2)>=0?1:-1,d=Math.sqrt(t*t+i*i+a*a),m=n.PAULI_X.times(t).plus(n.PAULI_Y.times(i)).plus(n.PAULI_Z.times(a)),f=(u=o.snappedCosSin(l*d)[Symbol.iterator](),(s=u.next()).done?void 0:s.value),h=(s=u.next()).done?void 0:s.value,g=new e(1+f,h).times(.5),p=new e(Math.sin(d/2)*c(d/2),-l*c(d)).times(.5*l);return n.identity(2).times(g).minus(m.times(p)).transformRealAndImagComponentsWith(function(e){return r.simplifyByRounding(e,1e-13)})},fromWireSwap:function(e,t,r){return n.generateTransition(1<<e,function(e){var n=1<<t,i=1<<r,a=e&~(n|i);return 0!=(e&n)&&(a|=i),0!=(e&i)&&(a|=n),a})},identity:function(e){if(!Number.isInteger(e)||e<=0)throw new t("Bad size",{size:e});for(var r=new Float64Array(e*e*2),i=0;i<e;i++)r[i*(e+1)*2]=1;return new n(e,e,r)},rotation:function(e){var t=Math.cos(e),r=Math.sin(e);return n.square(t,-r,r,t)},fromAngleAxisPhaseRotation:function(t,r,i){var a,u,s,c,l=(a=r[Symbol.iterator](),(u=a.next()).done?void 0:u.value),d=(u=a.next()).done?void 0:u.value,m=(u=a.next()).done?void 0:u.value;o.need(Math.abs(l*l+d*d+m*m-1)<1e-6,"Not a unit axis.");var f=n.PAULI_X.times(l).plus(n.PAULI_Y.times(d)).plus(n.PAULI_Z.times(m)),h=(s=o.snappedCosSin(-t/2)[Symbol.iterator](),(c=s.next()).done?void 0:c.value),g=(c=s.next()).done?void 0:c.value;return n.identity(2).times(h).plus(f.times(new e(0,g))).times(e.polar(1,i))}})}();return u.PAULI_X=u.square(0,1,1,0),u.PAULI_Y=u.square(0,new e(0,-1),e.I,0),u.PAULI_Z=u.square(1,0,0,-1),u.HADAMARD=u.square(1,1,1,-1).times(Math.sqrt(.5)),{get Matrix(){return u}}}),$traceurRuntime.registerModule("src/math/Point.js",[],function(){"use strict";var e=function(){function e(e,t){this.x=e,this.y=t}return $traceurRuntime.createClass(e,{isEqualTo:function(t){if(!(t instanceof e))return!1;var r=t;return r.x===this.x&&r.y===this.y},toString:function(){return"(x: "+this.x+", y: "+this.y+")"},offsetBy:function(t,r){return new e(this.x+t,this.y+r)},plus:function(t){return new e(this.x+t.x,this.y+t.y)},minus:function(t){return new e(this.x-t.x,this.y-t.y)},times:function(t){return new e(this.x*t,this.y*t)},distanceTo:function(e){var t=this.x-e.x,r=this.y-e.y;return Math.sqrt(t*t+r*r)}},{})}();return{get Point(){return e}}}),$traceurRuntime.registerModule("src/math/Rect.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/math/Rect.js")).Point,t=function(){function t(e,t,r,n){this.x=e,this.y=t,this.w=r,this.h=n}return $traceurRuntime.createClass(t,{isEqualTo:function(e){if(!(e instanceof t))return!1;var r=e;return r.x===this.x&&r.y===this.y&&r.w===this.w&&r.h===this.h},isApproximatelyEqualTo:function(e,r){if(!(e instanceof t))return!1;var n=e;return Math.abs(n.x-this.x)<=r&&Math.abs(n.y-this.y)<=r&&Math.abs(n.right()-this.right())<=r&&Math.abs(n.bottom()-this.bottom())<=r},toString:function(){return"["+this.x+":"+this.right()+"]x["+this.y+":"+this.bottom()+"]"},center:function(){return new e(this.x+this.w/2,this.y+this.h/2)},topLeft:function(){return new e(this.x,this.y)},topRight:function(){return new e(this.x+this.w,this.y)},bottomLeft:function(){return new e(this.x,this.y+this.h)},bottomRight:function(){return new e(this.x+this.w,this.y+this.h)},centerLeft:function(){return new e(this.x,this.y+this.h/2)},centerRight:function(){return new e(this.x+this.w,this.y+this.h/2)},topCenter:function(){return new e(this.x+this.w/2,this.y)},bottomCenter:function(){return new e(this.x+this.w/2,this.y+this.h)},right:function(){return this.x+this.w},bottom:function(){return this.y+this.h},skipLeft:function(e){var r=Math.min(e,this.w);return new t(this.x+r,this.y,this.w-r,this.h)},skipRight:function(e){var r=Math.min(e,this.w);return new t(this.x,this.y,this.w-r,this.h)},skipTop:function(e){var r=Math.min(e,this.h);return new t(this.x,this.y+r,this.w,this.h-r)},skipBottom:function(e){var r=Math.min(e,this.h);return new t(this.x,this.y,this.w,this.h-r)},takeLeft:function(e){var r=Math.max(e,0);return new t(this.x,this.y,r,this.h)},takeRight:function(e){var r=Math.max(e,0);return new t(this.x+this.w-r,this.y,r,this.h)},takeTop:function(e){var r=Math.max(e,0);return new t(this.x,this.y,this.w,r)},takeBottom:function(e){var r=Math.max(e,0);return new t(this.x,this.y+this.h-r,this.w,r)},paddedBy:function(e){return new t(this.x-e,this.y-e,this.w+2*e,this.h+2*e)},scaledOutwardBy:function(e){var r=this.center(),n=this.w*e,i=this.h*e;return new t(r.x-n/2,r.y-i/2,n,i)},containsPoint:function(e){return e.x>=this.x&&e.x<this.x+this.w&&e.y>=this.y&&e.y<this.y+this.h},takeLeftProportion:function(e){return this.takeLeft(this.w*e)},takeRightProportion:function(e){return this.takeRight(this.w*e)},takeTopProportion:function(e){return this.takeTop(this.h*e)},takeBottomProportion:function(e){return this.takeBottom(this.h*e)},leftHalf:function(){return this.skipRight(this.w/2)},rightHalf:function(){return this.skipLeft(this.w/2)},topHalf:function(){return this.skipBottom(this.h/2)},bottomHalf:function(){return this.skipTop(this.h/2)},shiftedBy:function(e,r){return new t(this.x+e,this.y+r,this.w,this.h)},proportionalShiftedBy:function(e,t){return this.shiftedBy(e*this.w,t*this.h)},withX:function(e){return new t(e,this.y,this.w,this.h)},withY:function(e){return new t(this.x,e,this.w,this.h)},withW:function(e){return new t(this.x,this.y,e,this.h)},withH:function(e){return new t(this.x,this.y,this.w,e)},snapInside:function(e){var r=Math.min(e.w,this.w),n=Math.min(e.h,this.h);return new t(Math.max(Math.min(this.x,e.right()-r),e.x),Math.max(Math.min(this.y,e.bottom()-n),e.y),r,n)}},{centeredSquareWithRadius:function(e,r){return new t(e.x-r,e.y-r,2*r,2*r)}})}();return{get Rect(){return t}}}),$traceurRuntime.registerModule("src/ui/clear.js",[],function(){"use strict";function e(e,r){var n=document.getElementById("clear-all-button");e.latestActiveCommit().zipLatest(r,function(e,t){return{r:e,v:t}}).subscribe(function(e){var t=e,r=t.r,i=t.v;n.disabled='{"cols":[]}'===r||i}),n.addEventListener("click",function(){return e.commit('{"cols":[]}')});var i=document.getElementById("clear-circuit-button");e.latestActiveCommit().zipLatest(r,function(e,t){return{r:e,v:t}}).subscribe(function(r){var n=r,a=n.r,o=n.v;i.disabled=a===t(e)||o}),i.addEventListener("click",function(){return e.commit(t(e))})}function t(e){var t=JSON.parse(e.peekActiveCommit());return t.cols=[],JSON.stringify(t)}return{get initClear(){return e}}}),$traceurRuntime.registerModule("src/ui/DisplayedCircuit.js",[],function(){"use strict";function e(e,t,r,n,a){var o=new M(0,t,void 0,void 0,void 0),u=o.desiredWidth(!0),s=o.desiredHeight(!0),c=r.w/u,l=r.h/s;if(n){var d=Math.min(c,l);c=d,l=d}var f=i.withNanDataFromCircuitAtTime(t,a);try{e.ctx.save(),e.ctx.translate(r.x,r.y),e.ctx.scale(Math.min(1,c),Math.min(1,l)),e.ctx.translate(0,0),o.paint(e,m.EMPTY,f,!0,n)}finally{e.ctx.restore()}return{maxW:u*c,maxH:s*l}}function t(e,t,r,n,i){var a=e.ctx;a.save(),a.textAlign="left",a.textBaseline="middle",e.ctx.font="12px monospace";var o=Math.max(e.ctx.measureText(n(0)).width,e.ctx.measureText(n(r-1)).width),u=2.5*a.measureText("0").width,s=Math.min(Math.min((i-2)/o,t/u),1),c=t/s,l=1/s;if(a.scale(s,s),a.translate(0,.5*t/s-.5*u),a.fillStyle="lightgray",u<.95*c)for(var d=0;d<r;d++)a.fillRect(0,c*d,o+2*l,u);else a.fillRect(0,0,o+2*l,c*r);a.fillStyle="black";for(var m=0;m<r;m++)a.fillText(n(m),l,.5*u+c*m);a.restore()}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/CachablePainting.js","src/ui/DisplayedCircuit.js")).CachablePainting,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/ui/DisplayedCircuit.js")).CircuitDefinition,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitStats.js","src/ui/DisplayedCircuit.js")).CircuitStats,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/DisplayedCircuit.js")).Config,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/ui/DisplayedCircuit.js")).DetailedError,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Equate.js","src/ui/DisplayedCircuit.js")).equate,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/ui/DisplayedCircuit.js")).Format,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateColumn.js","src/ui/DisplayedCircuit.js")).GateColumn,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GateDrawParams.js","src/ui/DisplayedCircuit.js")).GateDrawParams,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/ui/DisplayedCircuit.js")).GatePainting,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/Hand.js","src/ui/DisplayedCircuit.js")).Hand,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/ui/DisplayedCircuit.js")).MathPainter,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/ui/DisplayedCircuit.js")).Point,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/ui/DisplayedCircuit.js")).Matrix,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/ui/DisplayedCircuit.js")).Rect,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/ui/DisplayedCircuit.js")).Util,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/ui/DisplayedCircuit.js")),b=y.seq,R=y.Seq,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/BlochSphereDisplay.js","src/ui/DisplayedCircuit.js")).paintBlochSphereDisplay,M=function(){function e(e,t,r,i,a){if(!Number.isFinite(e))throw new o("Bad top",{top:e,circuitDefinition:t});if(!(t instanceof n))throw new o("Bad circuitDefinition",{top:e,circuitDefinition:t});this.top=e,this.circuitDefinition=t,this._compressedColumnIndex=r,this._highlightedSlot=i,this._extraWireStartIndex=a}return $traceurRuntime.createClass(e,{isBeingEdited:function(){return void 0!==this._extraWireStartIndex},_groundedWireCount:function(){var e=void 0!==this._extraWireStartIndex&&this._extraWireStartIndex!==a.MAX_WIRE_COUNT?1:0,t=Math.max(a.MIN_WIRE_COUNT,this.circuitDefinition.numWires)-e;return Math.max(t,this.circuitDefinition.minimumRequiredWireCount())},desiredHeight:function(){return void 0!==arguments[0]&&arguments[0]?this.circuitDefinition.numWires*a.WIRE_SPACING:this._groundedWireCount()*a.WIRE_SPACING+55},desiredWidth:function(){return void 0!==arguments[0]&&arguments[0]?this.opRect(this.circuitDefinition.columns.length-1).right()+35:this._rectForSuperpositionDisplay().right()+101},wireRect:function(e){if(e<0)throw new o("Bad wireIndex",{wireIndex:e});return new p(0,this.top+a.WIRE_SPACING*e,1/0,a.WIRE_SPACING)},wireIndexAt:function(e){return Math.floor((e-this.top)/a.WIRE_SPACING)},toColumnSpaceCoordinate:function(e){return(e-30)/(10+2*a.GATE_RADIUS)-.5},indexOfDisplayedRowAt:function(e){var t=Math.floor((e-this.top)/a.WIRE_SPACING);if(!(t<0||t>=this.circuitDefinition.numWires))return t},indexOfDisplayedColumnAt:function(e){var t,r=this.toColumnSpaceCoordinate(e);if(!((t=void 0===this._compressedColumnIndex||r<this._compressedColumnIndex-.75?Math.round(r):r<this._compressedColumnIndex-.25?this._compressedColumnIndex:Math.round(r)-1)<0||t>=this.circuitDefinition.columns.length))return t},findOpHalfColumnAt:function(e){if(!(e.x<0||e.y<this.top||e.y>this.top+this.desiredHeight()))return Math.max(-.5,Math.round(2*this.toColumnSpaceCoordinate(e.x))/2)},_findModificationIndex_helperColRow:function(e){if(void 0!==e.pos&&void 0!==e.heldGate){var t=e.pos.minus(e.holdOffset).plus(new h(a.GATE_RADIUS,a.GATE_RADIUS)),r=this.findOpHalfColumnAt(t),n=this.indexOfDisplayedRowAt(t.y);if(void 0!==r&&void 0!==n)return{col:Math.ceil(r),row:n,halfColIndex:r}}},findModificationIndex:function(e){var t=this._findModificationIndex_helperColRow(e);if(void 0!==t){var r=t,n=r.col,i=r.row,a=r.halfColIndex,o=.5===Math.abs(a%1);return n>=this.circuitDefinition.columns.length?{col:n,row:i,isInsert:o}:(o||this.circuitDefinition.isSlotRectCoveredByGateInSameColumn(n,i,e.heldGate.height)&&(o=!0,e.pos.x>this.opRect(n).center().x&&(n+=1)),{col:n,row:i,isInsert:o})}},opRect:function(e){var t=2*a.GATE_RADIUS,r=t+10,n=0;return void 0!==this._compressedColumnIndex&&e===this._compressedColumnIndex&&(n=r/2),void 0!==this._compressedColumnIndex&&e>this._compressedColumnIndex&&(n=r),new p(r*e-n+35,this.top,t,this.desiredHeight())},gateRect:function(e,t){var r=void 0!==arguments[2]?arguments[2]:1,n=void 0!==arguments[3]?arguments[3]:1,i=this.opRect(t),o=this.wireRect(e),u=new p(i.center().x-a.GATE_RADIUS,o.center().y-a.GATE_RADIUS,2*a.GATE_RADIUS+(r-1)*a.WIRE_SPACING,2*a.GATE_RADIUS+(n-1)*a.WIRE_SPACING);return new p(Math.round(u.x-.5)+.5,Math.round(u.y-.5)+.5,Math.round(u.w),Math.round(u.h))},afterTidyingUp:function(){return this.withCircuit(this.circuitDefinition.withUncoveredColumnsRemoved().withHeightOverlapsFixed().withWidthOverlapsFixed().withUncoveredColumnsRemoved().withTrailingSpacersIncluded())._withCompressedColumnIndex(void 0)._withExtraWireStartIndex(void 0)._withHighlightedSlot(void 0)},isEqualTo:function(t){return this===t||t instanceof e&&this.top===t.top&&this.circuitDefinition.isEqualTo(t.circuitDefinition)&&this._compressedColumnIndex===t._compressedColumnIndex&&this._extraWireStartIndex===t._extraWireStartIndex&&u(this._highlightedSlot,t._highlightedSlot)},paint:function(e,t,r){var n=void 0!==arguments[3]&&arguments[3];(void 0===arguments[4]||arguments[4])&&this._drawWires(e,!n);for(var i=0;i<this.circuitDefinition.columns.length;i++)this._drawColumn(e,this.circuitDefinition.columns[i],i,t,r);n||(this._drawOutputDisplays(e,r,t),this._drawHintLabels(e,r))},_drawWires:function(e,t){var r=this,n=Math.min(this.circuitDefinition.numWires,(this._extraWireStartIndex||1/0)+1);if(t)for(var i=0;i<n;i++){var o=this.wireRect(i).center().y;e.print("|0⟩",20,o,"right","middle","black","14px sans-serif",20,a.WIRE_SPACING)}e.ctx.save();for(var u=this,s=0;s<n;s++)!function(n){n===u._extraWireStartIndex&&(e.ctx.globalAlpha*=.5),e.trace(function(i){for(var a=r.wireRect(n),o=Math.round(a.center().y-.5)+.5,u=t?25:5,s=0;t?u<e.canvas.width:s<=r.circuitDefinition.columns.length;s++){var c=r.opRect(s).center().x;r.circuitDefinition.locIsMeasured(new h(s,n))?(i.line(u,o-1,c,o-1),i.line(u,o+1,c,o+1)):i.line(u,o,c,o),u=c}}).thenStroke("black")}(s);e.ctx.restore(),void 0!==this._extraWireStartIndex&&this.circuitDefinition.numWires===a.MAX_WIRE_COUNT&&e.print("(Max wires. Qubit limit is "+a.MAX_WIRE_COUNT+".)",5,this.wireRect(a.MAX_WIRE_COUNT).y,"left","top","red","16px bold monospace",400,a.WIRE_SPACING)},_highlightStatusAt:function(e,t,r){var n=this;if(void 0!==this._highlightedSlot&&this._highlightedSlot.col===e&&this._highlightedSlot.row===t)return{isResizeShowing:!0,isResizeHighlighted:this._highlightedSlot.resizeStyle,isHighlighted:!this._highlightedSlot.resizeStyle};var i=this.circuitDefinition.gateInSlot(e,t);if(void 0===i||void 0!==this._highlightedSlot)return{isResizeShowing:!1,isResizeHighlighted:!1,isHighlighted:!1};var a=this.gateRect(t,e,i.width,i.height),o=d.rectForResizeTab(a),u=function(r){var i=n.findGateOverlappingPos(r);return void 0===i||i.col===e&&i.row===t},s=i.canChangeInSize()&&b(r).any(function(e){return u(e)&&o.containsPoint(e)}),c=!s&&b(r).any(function(r){var i=n.findGateOverlappingPos(r);return void 0!==i&&i.col===e&&i.row===t});return{isHighlighted:c,isResizeShowing:i.canChangeInSize()&&(s||c),isResizeHighlighted:s}},_drawGate_disabledReason:function(e,t,r,n,i){var a=this.circuitDefinition.gateAtLocIsDisabledReason(t,r);if(void 0!==a){e.ctx.save(),i&&(e.ctx.globalAlpha*=.3),e.ctx.globalAlpha*=.5,e.fillRect(n.paddedBy(5),"yellow"),e.ctx.globalAlpha*=2,e.strokeLine(n.topLeft(),n.bottomRight(),"orange",3);var o=e.printParagraph(a,n.paddedBy(5),new h(.5,.5),"red");e.ctx.globalAlpha*=.5,e.fillRect(o.paddedBy(2),"yellow"),e.ctx.globalAlpha*=2,e.printParagraph(a,n.paddedBy(5),new h(.5,.5),"red"),e.ctx.restore()}},_drawColumn:function(e,t,r,n,i){this._drawColumnControlWires(e,r),this._drawColumnDragHighlight(e,r);for(var a=0;a<this.circuitDefinition.numWires;a++)if(void 0!==t.gates[a]){var o=t.gates[a],u=this.gateRect(a,r,o.width,o.height),s=this._highlightStatusAt(r,a,n.hoverPoints()),c=s.isHighlighted,m=s.isResizeShowing,f=s.isResizeHighlighted,h=o.customDrawer||d.DEFAULT_DRAWER;e.noteTouchBlocker({rect:u,cursor:"pointer"}),o.canChangeInSize()&&e.noteTouchBlocker({rect:d.rectForResizeTab(u),cursor:"ns-resize"}),h(new l(e,!1,c&&!f,m,f,u,o,i,{row:a,col:r},void 0===this._highlightedSlot?n.hoverPoints():[],i.customStatsForSlot(r,a))),this._drawGate_disabledReason(e,r,a,u,c)}this._drawColumnSurvivalRate(e,t,r,i)},_drawColumnSurvivalRate:function(e,t,r,n){if(void 0!==t.indexOfNonUnitaryGate()){var i=n.survivalRate(r-1),a=(n.survivalRate(r)-i)/i;if(!(isNaN(a)||Math.abs(a)<=.005)){var o,u;if(a<0){var s=Math.round(100*-a);o=(-1===a?"100":s<100?s:">99")+"%",u="omits"}else o=Math.round(100*a+100)+"%",u="gains";var c=this.opRect(r).bottomCenter();e.print(u,c.x,c.y-28,"center","bottom","red","14px sans-serif",800,50),e.print(o,c.x,c.y-13,"center","bottom","red","14px sans-serif",800,50)}}},_drawColumnDragHighlight:function(e,t){if(void 0!==this._highlightedSlot&&this._highlightedSlot.col===t&&void 0===this._highlightedSlot.row){var r=this.gateRect(0,t,1,this._groundedWireCount()).paddedBy(3);e.fillRect(r,"rgba(255, 196, 112, 0.7)"),e.strokeRect(r,"black")}},_drawColumnControlWires:function(e,t){var r=Math.round(this.opRect(t).center().x-.5)+.5;this.circuitDefinition.columns[t].hasGatesWithGlobalEffects()&&(e.ctx.save(),e.ctx.setLineDash([1,4]),e.strokeLine(new h(r,this.gateRect(0,0).y),new h(r,this.opRect(0).bottom()-40)),e.ctx.restore());var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=this.circuitDefinition.controlLinesRanges(t)[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=s.first,l=s.last,d=s.measured,m=this.wireRect(c).center().y,f=this.wireRect(l).center().y;d?(e.strokeLine(new h(r+1,m),new h(r+1,f)),e.strokeLine(new h(r-1,m),new h(r-1,f))):e.strokeLine(new h(r,m),new h(r,f))}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}},previewDrop:function(e){return void 0!==e.heldColumn?this._previewDropMovedGateColumn(e):void 0!==e.heldGate?this._previewDropMovedGate(e):this._previewResizedGate(e)},_previewDropMovedGateColumn:function(e){if(void 0===e.pos)return this;var t=this.findOpHalfColumnAt(new h(e.pos.x,this.top));t%1==0&&void 0!==this.circuitDefinition.columns[t]&&!this.circuitDefinition.columns[t].isEmpty()&&(t+=e.pos.x>this.opRect(t).center().x?.5:-.5);var r=Math.ceil(t),n=t%1!=0,i=Math.round((e.pos.y-e.holdOffset.y-this.top)/a.WIRE_SPACING),o=this._shiftAndSpliceColumn(i,$traceurRuntime.spread(e.heldColumn.gates),r,n);return this.withCircuit(o)._withHighlightedSlot({row:void 0,col:r,resizeStyle:!1})._withCompressedColumnIndex(n?r:void 0)},_shiftAndSpliceColumn:function(e,t,r,n){for(;e<0&&void 0===t[0];)t.shift(),t.push(void 0),e+=1;for(;e>0&&new c(t).minimumRequiredWireCount()<a.MAX_WIRE_COUNT;)t.unshift(void 0),new c(t).minimumRequiredWireCount()<t.length&&t.pop(),e-=1;for(var i=this.circuitDefinition.withWireCount(t.length),o=$traceurRuntime.spread(i.columns);o.length<r;)o.push(c.empty(i.numWires));return o.splice(r,n?0:1,new c(t)),i.withColumns(o).withTrailingSpacersIncluded()},_previewDropMovedGate:function(e){var t=this.findModificationIndex(e);if(void 0===t)return this;var r=Math.floor(e.holdOffset.y/a.WIRE_SPACING);if(t.row+r>=this.circuitDefinition.numWires)return this;var n=e.heldGate,i=c.empty(this.circuitDefinition.numWires),o=t.col,u=t.isInsert,s=Math.min(t.row,Math.max(0,a.MAX_WIRE_COUNT-n.height)),l=b(this.circuitDefinition.columns).padded(o,i).ifThen(u,function(e){return e.withInsertedItem(o,i)}).padded(o+n.width,i).withTransformedItem(o,function(e){return e.withGatesAdded(s,new c([n]))}).toArray(),d=Math.max(this._extraWireStartIndex||0,Math.max(this.circuitDefinition.numWires,n.height+s));if(d>a.MAX_WIRE_COUNT)return this;var m=this.circuitDefinition.withColumns(l).withWireCount(d);return this.withCircuit(m)._withHighlightedSlot({row:s,col:t.col,resizeStyle:!1})._withCompressedColumnIndex(u?o:void 0)._withFallbackExtraWireStartIndex(this.circuitDefinition.numWires)},_previewResizedGate:function(e){if(void 0===e.resizingGateSlot||void 0===e.pos)return this;var t=this.circuitDefinition.gateInSlot(e.resizingGateSlot.x,e.resizingGateSlot.y);if(void 0===t)return this;var r=Math.min(this.wireIndexAt(e.pos.y-e.holdOffset.y),a.MAX_WIRE_COUNT-1),n=b(t.gateFamily).minBy(function(t){return Math.abs(t.height-(r-e.resizingGateSlot.y+1))}),i=Math.min(a.MAX_WIRE_COUNT,Math.max(this.circuitDefinition.numWires,n.height+e.resizingGateSlot.y)),o=b(this.circuitDefinition.columns).withTransformedItem(e.resizingGateSlot.x,function(t){return new c(b(t.gates).withOverlayedItem(e.resizingGateSlot.y,n).toArray())}).toArray(),u=this.circuitDefinition.withColumns(o).withWireCount(i),s=u.withHeightOverlapsFixed(),l=s.withTrailingSpacersIncluded();return this.withCircuit(l)._withHighlightedSlot(this._highlightedSlot)._withCompressedColumnIndex(u.isEqualTo(s)?void 0:e.resizingGateSlot.x+1)._withFallbackExtraWireStartIndex(this.circuitDefinition.numWires)},afterDropping:function(e){return this.previewDrop(e)._withCompressedColumnIndex(void 0)},withCircuit:function(t){return new e(this.top,t,this._compressedColumnIndex,this._highlightedSlot,this._extraWireStartIndex)},_withCompressedColumnIndex:function(t){return new e(this.top,this.circuitDefinition,t,this._highlightedSlot,this._extraWireStartIndex)},_withHighlightedSlot:function(t){return new e(this.top,this.circuitDefinition,this._compressedColumnIndex,t,this._extraWireStartIndex)},_withExtraWireStartIndex:function(t){return new e(this.top,this.circuitDefinition,this._compressedColumnIndex,this._highlightedSlot,t)},_withFallbackExtraWireStartIndex:function(e){return this._withExtraWireStartIndex(this._extraWireStartIndex||e)},withJustEnoughWires:function(e,t){var r=void 0!==e.heldGate?e.heldGate.height:0,n=this.circuitDefinition.minimumRequiredWireCount(),i=Math.min(a.MAX_WIRE_COUNT,Math.max(Math.min(1,r),Math.max(a.MIN_WIRE_COUNT,n)+t));return this.withCircuit(this.circuitDefinition.withWireCount(i))._withExtraWireStartIndex(0===t?void 0:this.circuitDefinition.numWires)},findGateOverlappingPos:function(e){var t=this.indexOfDisplayedColumnAt(e.x),r=this.indexOfDisplayedRowAt(e.y);if(void 0!==t&&void 0!==r){var n=this.circuitDefinition.findGateCoveringSlot(t,r);if(void 0!==n){var i=this.gateRect(n.row,n.col,n.gate.width,n.gate.height);if(i.containsPoint(e))return{col:n.col,row:n.row,offset:e.minus(i.topLeft())}}}},findGateWithButtonContaining:function(e){var t=this.findGateOverlappingPos(e);if(void 0!==t){var r=this.circuitDefinition.gateInSlot(t.col,t.row);if(void 0!==r.onClickGateFunc&&d.gateButtonRect(this.gateRect(t.row,t.col,r.width,r.height)).containsPoint(e))return{col:t.col,row:t.row,gate:r}}},tryClick:function(e){if(void 0!==e.pos){var t=this.findGateWithButtonContaining(e.pos);if(void 0!==t){var r=t.gate.onClickGateFunc(t.gate),n=$traceurRuntime.spread(this.circuitDefinition.columns),i=n[t.col],a=$traceurRuntime.spread(i.gates);return a.splice(t.row,1,r),n.splice(t.col,1,new c(a)),this.withCircuit(this.circuitDefinition.withColumns(n))}}},tryGrab:function(e){var t=void 0!==arguments[1]&&arguments[1],r=void 0!==arguments[2]&&arguments[2],n=void 0!==arguments[3]&&arguments[3];if(r)return this._tryGrabWholeColumn(e,t)||{newCircuit:this,newHand:e};var i=e,a=this;if(!n){var o=this._tryGrabResizeTab(e);void 0!==o&&(i=o.newHand,a=o.newCircuit)}return a._tryGrabGate(i,t)||{newCircuit:a,newHand:i}},_tryGrabGate:function(t){var r=void 0!==arguments[1]&&arguments[1];if(!t.isBusy()&&void 0!==t.pos){var n=this.findGateOverlappingPos(t.pos);if(void 0!==n){var i=n,a=i.col,o=i.row,u=i.offset,s=this.circuitDefinition.columns[a].gates[o],l=b(this.circuitDefinition.columns[a].gates).toArray();r||(l[o]=void 0);var d=b(this.circuitDefinition.columns).withOverlayedItem(a,new c(l)).toArray();return{newCircuit:new e(this.top,this.circuitDefinition.withColumns(d),void 0,void 0,this._extraWireStartIndex),newHand:t.withHeldGate(s,u)}}}},_tryGrabResizeTab:function(e){if(!e.isBusy()&&void 0!==e.pos)for(var t=0;t<this.circuitDefinition.columns.length;t++)for(var r=0;r<this.circuitDefinition.numWires;r++){var n=this.circuitDefinition.columns[t].gates[r];if(void 0!==n&&this._highlightStatusAt(t,r,e.hoverPoints()).isResizeHighlighted){var i=e.pos.minus(this.gateRect(r+n.height-1,t,1,1).center());return{newCircuit:this._withHighlightedSlot({col:t,row:r,resizeStyle:!0}),newHand:e.withResizeSlot(new h(t,r),i)}}}},_tryGrabWholeColumn:function(e,t){if(!e.isBusy()&&void 0!==e.pos){var r=Math.round(this.toColumnSpaceCoordinate(e.pos.x));if(!(r<0||r>=this.circuitDefinition.columns.length||this.circuitDefinition.columns[r].isEmpty())){var n=$traceurRuntime.spread(this.circuitDefinition.columns);t||n.splice(r,1,c.empty(this.circuitDefinition.numWires));var i=new h(0,this.wireIndexAt(e.pos.y)*a.WIRE_SPACING+a.WIRE_SPACING/2);return{newCircuit:this.withCircuit(this.circuitDefinition.withColumns(n)),newHand:e.withHeldGateColumn(this.circuitDefinition.columns[r],i)}}}},stableDuration:function(){return this.circuitDefinition.stableDuration()},importantWireCount:function(){return Math.max(this.circuitDefinition.numWires-(this._extraWireStartIndex===a.MAX_WIRE_COUNT?0:1),a.MIN_WIRE_COUNT,this.circuitDefinition.minimumRequiredWireCount())},_drawOutputDisplays:function(e,t,r){if(!(t.circuitDefinition.numWires>a.MAX_SIMULATION_WIRE_COUNT)){for(var n=this.clampedCircuitColCount()+1,i=n+1,o=this.importantWireCount(),u=0;u<o;u++){var s=t.controlledWireProbabilityJustAfter(u,1/0);f.paintProbabilityBox(e,s,this.gateRect(u,n),r.hoverPoints());var c=t.qubitDensityMatrix(1/0,u);void 0!==c&&w(e,c,this.gateRect(u,i),r.hoverPoints())}var l=this.wireRect(o-1).bottom(),d=this.opRect(n-1).x;e.printParagraph("Local wire states\n(Chance/Bloch)",new p(d,l+4,190,40),new h(.5,0),"gray"),this._drawOutputSuperpositionDisplay(e,t,r)}},clampedCircuitColCount:function(){return Math.max(this.circuitDefinition.columns.length,a.MIN_COL_COUNT+(void 0!==this._compressedColumnIndex?1:0))},_drawOutputSuperpositionDisplay:function(e,t,r){var n=this._outputStateAsMatrix(t),i=this._rectForSuperpositionDisplay(),o=this.importantWireCount();f.paintMatrix(e,n,i,o<a.SIMPLE_SUPERPOSITION_DRAWING_WIRE_THRESHOLD?a.SUPERPOSITION_MID_COLOR:void 0,"black",o<a.SIMPLE_SUPERPOSITION_DRAWING_WIRE_THRESHOLD?a.SUPERPOSITION_FORE_COLOR:void 0,a.SUPERPOSITION_BACK_COLOR);var u=function(e){return(e>=0?"+":"")+e.toFixed(2)};f.paintMatrixTooltip(e,n,i,r.hoverPoints(),function(e,t){return"Amplitude of |"+v.bin(t*n.width()+e,o)+"⟩"},function(e,t,r){return"val:"+r.toString(new s(!1,0,5,", "))},function(e,t,r){return"mag²:"+(100*r.norm2()).toFixed(4)+"%, phase:"+u(180*r.phase()/Math.PI)+"°"}),this._drawOutputSuperpositionDisplay_labels(e)},_drawOutputSuperpositionDisplay_labels:function(e){var t=this._rectForSuperpositionDisplay(),r=this.importantWireCount();x.paint(t.right(),t.y,e,r),S.paint(t.x,t.bottom(),e,r)},_outputStateAsMatrix:function(e){var t,r,n,i,a=this.importantWireCount(),o=e.finalState.rawBuffer();if(e.circuitDefinition.numWires!==a){var u=new Float32Array(2<<a);u.set(o.slice(0,u.length)),o=u}var s=(n=[1<<(t=[Math.floor(a/2),Math.ceil(a/2)][Symbol.iterator](),(r=t.next()).done?void 0:r.value),1<<((r=t.next()).done?void 0:r.value)][Symbol.iterator](),(i=n.next()).done?void 0:i.value),c=(i=n.next()).done?void 0:i.value;return new g(s,c,o)},_rectForSuperpositionDisplay:function(){var e,t,r,n,i=this.clampedCircuitColCount()+2+1,a=this.importantWireCount(),o=(r=[1<<(e=[Math.floor(a/2),Math.ceil(a/2)][Symbol.iterator](),(t=e.next()).done?void 0:t.value),1<<((t=e.next()).done?void 0:t.value)][Symbol.iterator](),(n=r.next()).done?void 0:n.value),u=(n=r.next()).done?void 0:n.value,s=this.gateRect(0,i),c=this.gateRect(a-1,i),l=new p(s.x,s.y,0,c.bottom()-s.y);return l.withW(l.h*(o/u))},_drawHintLabels:function(e,t){var r=this._rectForSuperpositionDisplay();e.print("Final amplitudes",r.right()+3,r.bottom()+3,"left","top","gray","12px sans-serif",100,20),0!==this.circuitDefinition.colIsMeasuredMask(1/0)&&e.printParagraph("(assuming measurement deferred)",new p(r.right()+3,r.bottom()+20,100,75),new h(.5,0),"red");var n=t.survivalRate(1/0);if(Math.abs(n-1)>.01){var i;if(n<1){var a=Math.round(100*n);i="kept: "+(0===n?"0":a>0?a:"<1")+"%"}else i="over-unity: "+Math.round(100*n)+"%";e.print(i,this._rectForSuperpositionDisplay().x-5,r.bottom()+50,"right","bottom","red","14px sans-serif",800,50)}}},{empty:function(t){return new e(t,new n(a.MIN_WIRE_COUNT,[]),void 0,void 0,void 0)},fromTextDiagram:function(t,r){var i=r.split("\n").map(function(e){var n=e.split("|");if(2!==n.length)throw new o("Bad diagram",{diagramText:r,gateMap:t});return n[1]}),u=b(i).skip(1).stride(2).map(function(e){return b(e).skip(1).stride(2).join("")}).join("\n");return{circuit:new e(10,n.fromTextDiagram(t,u),void 0,void 0,void 0),pts:R.naturals().takeWhile(function(e){return-1!==r.indexOf(e)}).map(function(e){var t=b(i).mapWithIndex(function(t,r){return{row:r,col:t.indexOf(e)}}).filter(function(e){return-1!==e.col}).single();return"^"===i[t.row][t.col+1]&&(t.row-=1,t.col+=1),new h(t.col*a.WIRE_SPACING/2+35.5,t.row*a.WIRE_SPACING/2+10.5)}).toArray()}}})}(),_=function(t){if(void 0!==t.gate.knownCircuit&&""===t.gate.symbol){var r=t.gate.stableDuration()===1/0?a.GATE_FILL_COLOR:a.TIME_DEPENDENT_HIGHLIGHT_COLOR;d.paintBackground(t,r),e(t.painter,t.gate.knownCircuitNested,t.rect,!1,t.stats.time),d.paintOutline(t),t.isHighlighted&&(t.painter.ctx.save(),t.painter.ctx.globalAlpha*=.9,t.painter.fillRect(t.rect,a.HIGHLIGHTED_GATE_FILL_COLOR),t.painter.ctx.restore()),d.paintOutline(t)}else t.gate.stableDuration()===1/0?d.DEFAULT_DRAWER(t):d.makeCycleDrawer()(t)},x=new r(function(e){return{width:50,height:(e-1)*a.WIRE_SPACING+2*a.GATE_RADIUS}},function(e,r){var n,i,a=(n=[Math.floor(r/2),Math.ceil(r/2)][Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=1<<o,s=a<4?"_".repeat(a):"_..";t(e,e.canvas.height/u,u,function(e){return v.bin(e,o)+s},50)}),S=new r(function(e){var t,r,n,i,o=(n=[1<<(t=[Math.floor(e/2),Math.ceil(e/2)][Symbol.iterator](),(r=t.next()).done?void 0:r.value),1<<((r=t.next()).done?void 0:r.value)][Symbol.iterator](),(i=n.next()).done?void 0:i.value),u=(i=n.next()).done?void 0:i.value;return{width:o*(((e-1)*a.WIRE_SPACING+2*a.GATE_RADIUS)/u),height:50}},function(e,r){var n,i,a=(n=[Math.floor(r/2),Math.ceil(r/2)][Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=1<<a,s=e.canvas.width/u;e.ctx.translate(u*s,0),e.ctx.rotate(Math.PI/2);var c=o<4?"_".repeat(o):".._";t(e,s,u,function(e){return c+v.bin(u-1-e,a)},50)});return{get DisplayedCircuit(){return M},get drawCircuitTooltip(){return e},get GATE_CIRCUIT_DRAWER(){return _}}}),$traceurRuntime.registerModule("src/ui/DisplayedInspector.js",[],function(){"use strict";$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/ui/DisplayedInspector.js")).CircuitDefinition,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitStats.js","src/ui/DisplayedInspector.js")).CircuitStats;var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/DisplayedInspector.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedCircuit.js","src/ui/DisplayedInspector.js")).DisplayedCircuit,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedToolbox.js","src/ui/DisplayedInspector.js")).DisplayedToolbox,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GateDrawParams.js","src/ui/DisplayedInspector.js")).GateDrawParams,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/ui/DisplayedInspector.js")).GatePainting,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/AllGates.js","src/ui/DisplayedInspector.js")).Gates,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/Hand.js","src/ui/DisplayedInspector.js")).Hand,u=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/ui/DisplayedInspector.js")).Painter,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/ui/DisplayedInspector.js")).Rect),s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/ui/DisplayedInspector.js")).Serializer,c=function(){function c(e,t,r,n,i){this.displayedCircuit=t,this.displayedToolboxTop=r,this.displayedToolboxBottom=n.withCustomGatesInserted(t.circuitDefinition.customGateSet),this.hand=i,this.drawArea=new u(0,0,0,0),this.updateArea(e)}return $traceurRuntime.createClass(c,{desiredWidth:function(){return Math.max(this.displayedToolboxTop.desiredWidth(),Math.max(this.displayedCircuit.desiredWidth(),this.displayedToolboxBottom.desiredWidth()))},updateArea:function(e){this.drawArea=e,this.displayedToolboxTop=this.displayedToolboxTop.withTop(0),this.displayedToolboxBottom=this.displayedToolboxBottom.withTop(this.drawArea.bottom()-this.displayedToolboxBottom.desiredHeight())},paint:function(t,r){t.fillRect(this.drawArea,e.BACKGROUND_COLOR),this.displayedToolboxTop.paint(t,r,this.hand),this.displayedToolboxBottom.paint(t,r,this.hand),this.displayedCircuit.paint(t,this.hand,r),this._paintHand(t,r),this._drawHint(t)},_paintHand:function(t,r){if(void 0!==this.hand.pos&&void 0!==this.hand.heldGate){var a=this.hand.heldGate,o=this.hand.pos.minus(this.hand.holdOffset),s=new u(Math.round(o.x-.5)+.5,Math.round(o.y-.5)+.5,2*e.GATE_RADIUS+e.WIRE_SPACING*(a.width-1),2*e.GATE_RADIUS+e.WIRE_SPACING*(a.height-1));(a.customDrawer||i.DEFAULT_DRAWER)(new n(t,!1,!0,!0,!1,s,a,r,void 0,[],void 0))}},isHandOverButtonKey:function(){if(void 0!==this.hand.pos){var e=this.displayedCircuit.findGateWithButtonContaining(this.hand.pos);return void 0===e?void 0:e.col+":"+e.row}},tryClick:function(){var e=this.displayedCircuit.tryClick(this.hand);return void 0===e?void 0:this.withDisplayedCircuit(e)},afterGrabbing:function(){var e=void 0!==arguments[0]&&arguments[0],t=void 0!==arguments[1]&&arguments[1],r=void 0!==arguments[2]&&arguments[2],n=this.hand,i=this.displayedCircuit;n=this.displayedToolboxTop.tryGrab(n),n=this.displayedToolboxBottom.tryGrab(n);var a=i.tryGrab(n,e,t,r);return n=a.newHand,i=a.newCircuit,new c(this.drawArea,i,this.displayedToolboxTop,this.displayedToolboxBottom,n)},isEqualTo:function(e){return this===e||e instanceof c&&this.drawArea.isEqualTo(e.drawArea)&&this.displayedCircuit.isEqualTo(e.displayedCircuit)&&this.displayedToolboxTop.isEqualTo(e.displayedToolboxTop)&&this.displayedToolboxBottom.isEqualTo(e.displayedToolboxBottom)&&this.hand.isEqualTo(e.hand)},withDisplayedCircuit:function(e){return e===this.displayedCircuit?this:new c(this.drawArea,e,this.displayedToolboxTop,this.displayedToolboxBottom,this.hand)},withJustEnoughWires:function(e,t){return this.withDisplayedCircuit(this.displayedCircuit.withJustEnoughWires(e,t))},afterTidyingUp:function(){return this.withDisplayedCircuit(this.displayedCircuit.afterTidyingUp())},previewDrop:function(){if(!this.hand.isBusy())return this;var e=this.hand,t=this.displayedCircuit,r=t.previewDrop(e),n=r===t?e:e.withDrop();return this.withHand(n).withDisplayedCircuit(r)},afterDropping:function(){return this.withDisplayedCircuit(this.displayedCircuit.afterDropping(this.hand)).withHand(this.hand.withDrop())},stableDuration:function(){return Math.min(this.displayedToolboxTop.stableDuration(this.hand),this.displayedToolboxBottom.stableDuration(this.hand),this.hand.stableDuration(),this.displayedCircuit.stableDuration())},withHand:function(e){return new c(this.drawArea,this.displayedCircuit,this.displayedToolboxTop,this.displayedToolboxBottom,e)},withCircuitDefinition:function(e){return new c(this.drawArea,t.empty(this.displayedToolboxTop.desiredHeight()).withCircuit(e),this.displayedToolboxTop,this.displayedToolboxBottom,this.hand.withDrop())},desiredHeight:function(){var t=this.displayedToolboxBottom.desiredHeight()+this.displayedToolboxTop.desiredHeight()+this.displayedCircuit.desiredHeight();return Math.max(e.MINIMUM_CANVAS_HEIGHT,t)},snapshot:function(){return JSON.stringify(s.toJson(this.displayedCircuit.circuitDefinition),null,0)},_drawHint:function(e){this._drawHint_dragGatesOntoCircuit(e),this._drawHint_watchOutputsChange(e),this._drawHint_useControls(e)},_watchOutputsChangeVisibility:function(){var e=this.displayedCircuit.circuitDefinition.countGatesUpTo(2),t=e+(this.hand.isBusy()?1:0);if(e>=2||0===t)return 0;var r=void 0===this.hand.pos?1/0:this.hand.pos.y;return 0===e?(r-125)/25:2===t?(150-r)/25:1},_drawHint_watchOutputsChange:function(e){var t=this._watchOutputsChangeVisibility();t<=0||(e.ctx.save(),e.ctx.globalAlpha*=Math.min(1,t),e.ctx.translate(this.displayedCircuit.opRect(this.displayedCircuit.clampedCircuitColCount()).x-280,15),e.ctx.save(),e.ctx.translate(268,250),e.ctx.rotate(.02*Math.PI),e.ctx.fillStyle="red",e.ctx.textAlign="right",e.ctx.font="16px sans-serif",e.ctx.fillText("outputs change",0,0),e.ctx.restore(),e.ctx.beginPath(),e.ctx.moveTo(270,245),e.ctx.bezierCurveTo(300,245,315,235,325,225),e.ctx.strokeStyle="red",e.ctx.lineWidth=3,e.ctx.stroke(),e.trace(function(e){e.arrowHead(330,219,10,-.265*Math.PI,1.3)}).thenFill("red"),e.ctx.restore())},_drawHint_dragGatesOntoCircuit:function(e){if(!this.displayedCircuit.circuitDefinition.hasNonControlGates()){var t=void 0!==this.hand.pos&&this.hand.isBusy()?void 0!==this.hand.heldGate&&this.hand.heldGate.isControl()?1:(150-this.hand.pos.y)/50:1;t<=0||(e.ctx.save(),e.ctx.globalAlpha*=Math.min(1,t),e.ctx.save(),e.ctx.translate(70,190),e.ctx.rotate(.05*Math.PI),e.ctx.fillStyle="red",e.ctx.font="16px sans-serif",e.ctx.fillText("drag gates onto circuit",0,0),e.ctx.restore(),e.ctx.beginPath(),e.ctx.moveTo(268,132),e.ctx.bezierCurveTo(260,170,235,175,217,187),e.ctx.strokeStyle="red",e.ctx.lineWidth=3,e.ctx.stroke(),e.trace(function(e){e.arrowHead(210,190,10,.84*Math.PI,1.3)}).thenFill("red"),e.ctx.restore())}},_useControlsHintVisibility:function(){var e=this.displayedCircuit.circuitDefinition,t=e.countGatesUpTo(2),r=t+(void 0!==this.hand.heldGate?1:0),n=e.gateInSlot(0,0);return e.hasControls()||!e.hasNonControlGates()||void 0!==n&&n.height>1?0:1!==t||1!==r||this.displayedCircuit.isBeingEdited()?1===t&&2===r&&this.displayedCircuit.isBeingEdited()?(150-this.hand.pos.y)/50:0:1},_drawHint_useControls:function(e){var t=this._useControlsHintVisibility();if(!(t<=0)){e.ctx.save(),e.ctx.globalAlpha*=Math.min(1,t);var r=void 0===this.displayedCircuit.circuitDefinition.gateInSlot(0,0),n=r?173:223;e.ctx.save(),e.ctx.translate(70,n-3),e.ctx.rotate(-.01*Math.PI),e.ctx.fillStyle="red",e.ctx.font="16px sans-serif",e.ctx.fillText("use controls",0,0),e.ctx.restore(),e.ctx.beginPath(),r?(e.ctx.moveTo(90,125),e.ctx.bezierCurveTo(60,140,48,160,55,n)):(e.ctx.moveTo(100,125),e.ctx.bezierCurveTo(115,150,105,170,55,n)),e.ctx.strokeStyle="red",e.ctx.lineWidth=3,e.ctx.stroke(),e.ctx.beginPath(),e.ctx.arc(55,n,5,0,2*Math.PI),e.ctx.fillStyle="red",e.ctx.fill(),e.ctx.restore()}}},{empty:function(e){var n=new r("Toolbox",0,a.TopToolboxGroups,!0,3),i=t.empty(n.desiredHeight());return new c(e,i,n,new r("Toolbox₂",i.top+i.desiredHeight(),a.BottomToolboxGroups,!1,4),o.EMPTY)}})}();return{get DisplayedInspector(){return c}}}),$traceurRuntime.registerModule("src/ui/DisplayedToolbox.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/CachablePainting.js","src/ui/DisplayedToolbox.js")).CachablePainting,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitStats.js","src/ui/DisplayedToolbox.js")).CircuitStats,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/DisplayedToolbox.js")).Config,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GateDrawParams.js","src/ui/DisplayedToolbox.js")).GateDrawParams,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/GatePainting.js","src/ui/DisplayedToolbox.js")).GatePainting,a=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/Hand.js","src/ui/DisplayedToolbox.js")).Hand,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/gates/Joke_MysteryGate.js","src/ui/DisplayedToolbox.js"))),o=a.MysteryGateSymbol,u=a.MysteryGateMaker,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/ui/DisplayedToolbox.js")).Rect,c=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/ui/DisplayedToolbox.js")).Painter,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/ui/DisplayedToolbox.js")).Point),l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/ui/DisplayedToolbox.js")).seq,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/WidgetPainter.js","src/ui/DisplayedToolbox.js")).WidgetPainter,m=function(){function a(t,r,n,i,a){var o=arguments[5],u=arguments[6],s=this;this.name=t,this.top=r,this.toolboxGroups=n,this.labelsOnTop=i,this.groupHeight=a,this._originalGroups=o||this.toolboxGroups,this._standardApperance=u||new e(function(){return{width:s.desiredWidth(),height:s.desiredHeight()}},function(e){e.ctx.save(),e.ctx.translate(0,-s.top),s._paintStandardContents(e),e.ctx.restore()})}return $traceurRuntime.createClass(a,{withCustomGatesInserted:function(e){for(var t=$traceurRuntime.spread(this._originalGroups),r=0;r<Math.max(1,e.gates.length);r+=2*this.groupHeight){for(var n={hint:"Custom Gates",gates:[void 0,void 0,void 0,void 0,void 0,void 0]},i=0;i<2*this.groupHeight&&r+i<e.gates.length;i++)n.gates[i]=e.gates[r+i];t.push(n)}return new a(this.name,this.top,t,this.labelsOnTop,this.groupHeight,this._originalGroups,this._standardApperance)},gateDrawRect:function(e,t){var n=t%2,i=Math.floor(t/2),a=r.TOOLBOX_MARGIN_X+n*r.TOOLBOX_GATE_SPAN+e*r.TOOLBOX_GROUP_SPAN,o=this.top+(this.labelsOnTop?r.TOOLBOX_MARGIN_Y:3)+i*r.TOOLBOX_GATE_SPAN;return new s(Math.round(a-.5)+.5,Math.round(o-.5)+.5,2*r.GATE_RADIUS,2*r.GATE_RADIUS)},groupLabelRect:function(e){if(this.labelsOnTop){var t=this.gateDrawRect(e,0),n=new c(t.x+r.TOOLBOX_GATE_SPAN-r.TOOLBOX_GATE_SPACING/2,t.y-18);return new s(n.x-r.TOOLBOX_GATE_SPAN,n.y,2*r.TOOLBOX_GATE_SPAN,20)}var i=this.gateDrawRect(e,2*this.groupHeight-2),a=new c(i.x+r.TOOLBOX_GATE_SPAN-r.TOOLBOX_GATE_SPACING/2,i.bottom());return new s(a.x-r.TOOLBOX_GATE_SPAN,a.y+2,2*r.TOOLBOX_GATE_SPAN,20)},findGateAt:function(e){if(void 0!==e)for(var t=0;t<this.toolboxGroups.length;t++)for(var r=this.toolboxGroups[t],n=0;n<r.gates.length;n++){var i=r.gates[n],a=this.gateDrawRect(t,n);if(void 0!==i&&a.containsPoint(e))return{groupIndex:t,gateIndex:n,gate:i,rect:a}}},isEqualTo:function(e){return e instanceof a&&this.name===e.name&&this.top===e.top&&this.toolboxGroups===e.toolboxGroups&&this.labelsOnTop===e.labelsOnTop},withTop:function(e){return new a(this.name,e,this.toolboxGroups,this.labelsOnTop,this.groupHeight,this._originalGroups,this._standardApperance)},curArea:function(e){return new s(0,this.top,e,this.desiredHeight())},paint:function(e,t,n){e.fillRect(this.curArea(e.canvas.width),r.BACKGROUND_COLOR_TOOLBOX),this._standardApperance.paint(0,this.top,e),this._paintDeviations(e,t,n)},_paintStandardContents:function(e){for(var t=0;t<this.toolboxGroups.length;t++)this._paintGatesInGroup(e,t);var n=this.curArea(r.TOOLBOX_MARGIN_X),i=n.center(),a=i.x,o=i.y;e.ctx.save(),e.ctx.translate(a,o),e.ctx.rotate(-Math.PI/2),e.printLine(this.name,new s(-n.h/2,-n.w/2,n.h,n.w),.5,"black",24),e.ctx.restore()},_paintDeviations:function(e,t,r){for(var n=0;n<this.toolboxGroups.length;n++){n>=this._originalGroups.length&&this._paintGatesInGroup(e,n);for(var i=this.toolboxGroups[n],a=0;a<i.gates.length;a++)void 0!==i.gates[a]&&e.noteTouchBlocker({rect:this.gateDrawRect(n,a),cursor:"pointer"})}this._paintFocus(e,t,r)},_paintGatesInGroup:function(e,r){var n=this.toolboxGroups[r],i=this.groupLabelRect(r);e.print(n.hint,i.x+i.w/2,i.y+i.h/2,"center","middle","black","16px sans-serif",i.w,i.h);for(var o=0;o<n.gates.length;o++){var u=n.gates[o];if(void 0!==u){var s=this.gateDrawRect(r,o);a._paintGate(e,u,s,!1,t.EMPTY)}}},_paintFocus:function(e,t,r){var n=this.findGateAt(r.pos);if(void 0!==n&&(void 0===r.heldGate||n.gate.symbol===r.heldGate.symbol)){a._paintGate(e,n.gate,n.rect,!0,t),e.ctx.save(),e.ctx.globalAlpha=0,e.ctx.translate(-1e4,-1e4);var i=d.paintGateTooltip(e,new s(0,0,500,300),n.gate,t.time,!0),o=i.maxW,u=i.maxH,c=o>=500||u>=300;e.ctx.restore();var l=n.rect.right()+1,m=new s(l,n.rect.center().y,o,u).snapInside(e.paintableArea().skipRight(10).skipBottom(20));e.defer(function(){return d.paintGateTooltip(e,m,n.gate,t.time,c)})}},desiredWidth:function(){return this.gateDrawRect(this.toolboxGroups.length-1,5).right()+5},desiredHeight:function(){return(1+this.groupHeight)*(2*r.GATE_RADIUS+2)-r.GATE_RADIUS},tryGrab:function(e){var t=this;if(void 0===e.pos||e.isBusy())return e;var n=this.findGateAt(e.pos);return void 0===n?e:(n.gate.symbol===o&&setTimeout(function(){t.toolboxGroups[n.groupIndex].gates[n.gateIndex]=u()},.1),e.withHeldGate(n.gate,new c(r.GATE_RADIUS,r.GATE_RADIUS)))},stableDuration:function(e){var t=this;return l(e.hoverPoints()).map(function(e){return t.findGateAt(e)}).filter(function(e){return void 0!==e}).map(function(e){return e.gate.stableDuration()}).min(1/0)}},{_paintGate:function(e,t,r,a,o){(t.customDrawer||i.DEFAULT_DRAWER)(new n(e,!0,a,!1,!1,r,t,o,void 0,[],void 0))}})}();return{get DisplayedToolbox(){return m}}}),$traceurRuntime.registerModule("src/ui/exports.js",[],function(){"use strict";function e(e,r){!function(){var e=document.getElementById("export-button"),t=document.getElementById("export-overlay"),n=document.getElementById("export-div");e.addEventListener("click",function(){return o.set(!0)}),r.subscribe(function(t){e.disabled=t}),t.addEventListener("click",function(){return o.set(!1)}),document.addEventListener("keydown",function(e){27===e.keyCode&&o.set(!1)}),u.subscribe(function(e){n.style.display=e?"block":"none",e&&document.getElementById("export-link-copy-button").focus()})}();var s=function(e,t,r){return e.addEventListener("click",function(){try{n(t),r.innerText="Done!"}catch(e){r.innerText="It didn't work...",console.warn("Clipboard copy failed.",e)}e.disabled=!0,setTimeout(function(){r.innerText="",e.disabled=!1},1e3)})};!function(){var r=document.getElementById("export-escaped-anchor"),n=document.getElementById("export-link-copy-button"),i=document.getElementById("export-link-copy-result");s(n,r,i),e.latestActiveCommit().subscribe(function(e){var n="#"+t.URL_CIRCUIT_PARAM_KEY+"="+encodeURIComponent(e);r.href=n,r.innerText=document.location.href.split("#")[0]+n})}(),function(){var t=document.getElementById("export-circuit-json-pre"),r=document.getElementById("export-json-copy-button"),n=document.getElementById("export-json-copy-result");s(r,t,n),e.latestActiveCommit().subscribe(function(e){try{var r=JSON.parse(e);t.innerText=JSON.stringify(r,null," ")}catch(r){t.innerText=e}})}(),function(){var t,r=document.getElementById("download-offline-copy-button"),n=function(e){try{var t=i(e);if(!t.isEmpty())return"Quirk with Circuit - "+t.readableHash()+".html"}catch(e){}return"Quirk.html"};e.latestActiveCommit().subscribe(function(e){r.innerText='Download "'+n(e)+'"',t=e}),r.addEventListener("click",function(){r.disabled=!0,setTimeout(function(){r.disabled=!1},1e3);var e=document.QUIRK_QUINE_ALL_HTML_ORIGINAL,i=e.indexOf("//DEFAULT_CIRCUIT_START\n"),o=e.indexOf("//DEFAULT_CIRCUIT_END\n",i),u=e.substring(0,i)+"//DEFAULT_CIRCUIT_START\ndocument.DEFAULT_CIRCUIT = "+JSON.stringify(t)+";\n"+e.substring(o),s=u.indexOf("\x3c!-- Start Analytics --\x3e\n");if(-1!==s){var c=u.indexOf("\x3c!-- End Analytics --\x3e\n",s);-1!==c&&(u=u.substring(0,s)+"\x3c!-- Start Analytics --\x3e\n"+u.substring(c))}a(n(t),u)})}()}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/exports.js")).Config,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/ui/exports.js")).ObservableValue,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/Clipboard.js","src/ui/exports.js")).selectAndCopyToClipboard,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/ui/exports.js")).fromJsonText_CircuitDefinition,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/SaveFile.js","src/ui/exports.js")).saveFile,o=new r(!1),u=o.observable().whenDifferent();return{get initExports(){return e},get obsExportsIsShowing(){return u}}}),$traceurRuntime.registerModule("src/ui/forge.js",[],function(){"use strict";function e(e,r){function n(e,t,r){r.disabled=!0;var n=new A(e);n.clear();var i=Math.min((e.width-5)/2,e.height),a=new $(0,0,i,i),o=new $(i+5,0,i,i);try{var u=t();M.paintMatrix(n,u,a,h.OPERATION_FORE_COLOR,"black",void 0,h.OPERATION_BACK_COLOR,void 0,"transparent"),u.isUnitary(.009)?2!==u.width()?n.printParagraph("(Not a 1-qubit rotation)",o,new C(.5,.5),"#666",20):M.paintBlochSphereRotation(n,u,o,h.OPERATION_BACK_COLOR,h.OPERATION_FORE_COLOR):n.printParagraph("NOT UNITARY",o,new C(.5,.5),"red",24);var s=(a.right()+o.x)/2;n.strokeLine(new C(s,0),new C(s,e.height),"black",2),u.hasNaN()||(r.disabled=!1)}catch(t){n.printParagraph(t+"",new $(0,0,e.width,e.height),new C(.5,.5),"red",24)}}function a(t){var r=arguments[1]||E(u);e.commit(JSON.stringify(I.toJson(r.withCustomGate(t)),null,0)),N.set(!1)}var u,s=O.filter(function(e){return!0===e});e.latestActiveCommit().subscribe(function(e){u=e}),function(){var e=document.getElementById("gate-forge-button"),t=document.getElementById("gate-forge-overlay"),n=document.getElementById("gate-forge-div");e.addEventListener("click",function(){return N.set(!0)}),t.addEventListener("click",function(){return N.set(!1)}),r.subscribe(function(t){e.disabled=t}),document.addEventListener("keydown",function(e){27===e.keyCode&&N.set(!1)}),O.subscribe(function(e){n.style.display=e?"block":"none",e&&document.getElementById("gate-forge-rotation-axis").focus()})}(),function(){function e(){return i(t(l),t(d),t(c))}var r,o=document.getElementById("gate-forge-rotation-canvas"),u=document.getElementById("gate-forge-rotation-button"),c=document.getElementById("gate-forge-rotation-axis"),l=document.getElementById("gate-forge-rotation-angle"),d=document.getElementById("gate-forge-rotation-phase"),m=document.getElementById("gate-forge-rotation-name");s.subscribe(function(){m.value=""});(r=S).of.apply(r,$traceurRuntime.spread([s],[d,c,l].map(P))).flatten().throttleLatest(100).subscribe(function(){return n(o,e,u)}),u.addEventListener("click",function(){var t;try{t=e()}catch(e){return void console.warn(e)}a((new b).setSerializedId("~"+Math.floor(Math.random()*(1<<20)).toString(32)).setSymbol(m.value).setTitle("Custom Rotation Gate").setKnownEffectToMatrix(t).gate)})}(),function(){function e(){return o(t(i),u.checked)}var r=document.getElementById("gate-forge-matrix-canvas"),i=document.getElementById("gate-forge-matrix"),u=document.getElementById("gate-forge-matrix-fix"),c=document.getElementById("gate-forge-matrix-button"),l=document.getElementById("gate-forge-matrix-name");s.subscribe(function(){l.value=""});S.of(s,P(i),S.elementEvent(u,"change")).flatten().throttleLatest(100).subscribe(function(){return n(r,e,c)}),c.addEventListener("click",function(){var t;try{t=e()}catch(e){return void console.warn(e)}var r=l.value.trim(),n=Math.round(Math.log2(t.height()));a((new b).setSerializedId("~"+Math.floor(Math.random()*(1<<20)).toString(32)).setSymbol(r).setTitle("Custom Matrix Gate").setHeight(n).setWidth(""===r?n:1).setKnownEffectToMatrix(t).gate)})}(),function(){function e(){var e=E(u);return{gate:c(e,t(n),t(i),m.value.trim()),circuit:e}}var r=document.getElementById("gate-forge-circuit-canvas"),n=document.getElementById("gate-forge-circuit-cols"),i=document.getElementById("gate-forge-circuit-rows"),o=document.getElementById("gate-forge-circuit-inputs"),l=document.getElementById("gate-forge-circuit-weight"),d=document.getElementById("gate-forge-circuit-button"),m=document.getElementById("gate-forge-circuit-name");s.subscribe(function(){m.value=""});var f=new T(void 0),h=function(e,t){return p(e,t.knownCircuitNested,new $(0,0,r.width,r.height),!0,w())};f.observable().zipLatest(O,function(e,t){return t?e:void 0}).map(function(e){return void 0===e||e.gate.stableDuration()===1/0?S.of():S.requestAnimationTicker().map(function(t){return e})}).flattenLatest().subscribe(function(e){var t=new A(r);t.clear(),h(t,e.gate)});S.of(s,P(n),P(i)).flatten().throttleLatest(100).subscribe(function(){d.disabled=!0;var t=new A(r);t.clear();try{var n=e().gate,i=n.getUnmetContextKeys();o.innerText=0===i.size?"(none)":$traceurRuntime.spread(i).map(function(e){return e.replace("Input Range ","").replace("Input NO_DEFAULT Range ","")}).join(", "),l.innerText=""+n.knownCircuit.gateWeight(),h(t,n),d.disabled=!1,f.set({gate:n})}catch(e){f.set(void 0),o.innerText="(err)",l.innerText="(err)",t.printParagraph(e+"",new $(0,0,r.width,r.height),new C(.5,.5),"red",24)}}),d.addEventListener("click",function(){try{var t=e();a(t.gate,t.circuit)}catch(e){console.warn(e)}})}()}function t(e){return""===e.value?e.placeholder:e.value}function r(e){var t=f.parse(e);if(0!==t.imag||isNaN(t.imag))throw new Error("You just had to make it complicated, didn't you?");return t.real*Math.PI/180}function n(e){return _.parse(e.toString(new v(!0,1e-7,7,",")))}function i(e,t,i){var a,o,u=r(e),s=r(t),c=l.parse(i),d=c.x,m=c.y,h=c.z,p=Math.sqrt(d*d+m*m+h*h);d/=p,m/=p,h/=p;var v=(a=[_.identity(2),_.PAULI_X,_.PAULI_Y,_.PAULI_Z][Symbol.iterator](),(o=a.next()).done?void 0:o.value),y=(o=a.next()).done?void 0:o.value,b=(o=a.next()).done?void 0:o.value,R=(o=a.next()).done?void 0:o.value,w=y.times(d).plus(b.times(m)).plus(R.times(h)),M=v.times(Math.cos(u/2)).plus(w.times(f.I.neg()).times(Math.sin(u/2))).times(f.polar(1,s));if(M.hasNaN())throw new g("NaN",{x:d,y:m,z:h,result:M});return n(M)}function a(e){var t;if(e.match(/[\{}\[\]]/))return _.parse(e.split(/[\{\[]/).join("{").split(/[}\]]/).join("}"));(e=(e=e.split(/,?\s*\n\s*(?!$)/).join(",")).trim()).endsWith(",")&&(e=e.substring(0,e.length-1));var r=e.split(",").map(function(e){return""===e?0:f.parse(e)});1===r.length&&r.push(0,0,r[0]);var n=Math.max(4,1<<2*Math.max(1,k.floorLg2(Math.sqrt(r.length))));if(n<r.length&&(n<<=2),n>256)throw Error("Max custom matrix operation size is 4 qubits.");return(t=_).square.apply(t,$traceurRuntime.spread(r,new Array(n-r.length).fill(0)))}function o(e,t){var r=a(e);if(r.width()!==r.height()||r.width()<2||r.width()>16||!k.isPowerOf2(r.width()))throw Error("Matrix must be 2x2, 4x4, 8x8, or 16x16.");return t&&!r.hasNaN()&&(r=n(r=r.closestUnitary(1e-4))),r}function u(e,t){var r=e.split(":").map(function(e){return e.trim()});if(r.length>2)throw new Error("Too many colons.");var n=[void 0,"","∞"],i=parseInt(r[0]||"1"),a=-1!==n.indexOf(r[1])?1/0:parseInt(r[1]);if(isNaN(i))throw new Error("Not a number: "+r[0]);if(isNaN(a))throw new Error("Not a number: "+r[1]);var o=Math.min(t,Math.max(0,i-1));return{start:o,end:Math.min(t,Math.max(o,a))}}function s(e){var t=e.columns.length,r=e.numWires;return e.withColumns(G(e.columns).mapWithIndex(function(e,n){return new R(G(e.gates).mapWithIndex(function(e,i){return void 0===e||n+e.width>t||i+e.height>r?void 0:e}).toArray())}).toArray())}function c(e,t,r,n){var i=u(t,e.columns.length),a=u(r,e.numWires);if(a.end===a.start)throw new Error("Empty wire range.");var o=e.columns.slice(i.start,i.end).map(function(e){return new R(e.gates.slice(a.start,a.end))}),c=new d(a.end-a.start,o);if(c=s(c),0===(c=c.withUncoveredColumnsRemoved()).columns.length)throw new Error("No gates in included range.");var l=n,f="~"+Math.floor(Math.random()*(1<<20)).toString(32);return m(new b,c).setSerializedId(f).setSymbol(l).setTitle(f).setBlurb("A custom gate.").gate}var l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Axis.js","src/ui/forge.js")).Axis,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/ui/forge.js")).CircuitDefinition,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitComputeUtil.js","src/ui/forge.js")).setGateBuilderEffectToCircuit,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Complex.js","src/ui/forge.js")).Complex,h=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/forge.js")).Config,g=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/ui/forge.js")).DetailedError,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/DisplayedCircuit.js","src/ui/forge.js")).drawCircuitTooltip,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Format.js","src/ui/forge.js")).Format,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/ui/forge.js")),b=(y.Gate,y.GateBuilder),R=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateColumn.js","src/ui/forge.js")).GateColumn,w=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/ui/sim.js","src/ui/forge.js")).getCircuitCycleTime,M=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/MathPainter.js","src/ui/forge.js")).MathPainter,_=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/ui/forge.js")).Matrix,x=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/ui/forge.js")),S=x.Observable,T=x.ObservableValue,A=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/draw/Painter.js","src/ui/forge.js")).Painter,C=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/ui/forge.js")).Point,$=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Rect.js","src/ui/forge.js")).Rect,j=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/ui/forge.js")),E=j.fromJsonText_CircuitDefinition,I=j.Serializer,G=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/ui/forge.js")).seq,P=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/EventUtil.js","src/ui/forge.js")).textEditObservable,k=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/ui/forge.js")).Util,N=new T(!1),O=N.observable().whenDifferent();return{get initForge(){return e},get obsForgeIsShowing(){return O},get parseUserRotation(){return i},get parseUserMatrix(){return o},get parseUserGateFromCircuitRange(){return c}}}),$traceurRuntime.registerModule("src/ui/Hand.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Describe.js","src/ui/Hand.js")).describe,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/ui/Hand.js")).DetailedError,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Gate.js","src/ui/Hand.js")).Gate,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/GateColumn.js","src/ui/Hand.js")).GateColumn,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Point.js","src/ui/Hand.js")).Point,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/ui/Hand.js")).Util,o=function(){function o(e,a,o,u,s){if(void 0!==e&&!(e instanceof i))throw new t("Bad pos",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});if(void 0!==a&&!(a instanceof r))throw new t("Bad heldGate",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});if(void 0!==o&&!(o instanceof i))throw new t("Bad holdOffset",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});if(void 0!==s&&!(s instanceof i))throw new t("Bad resizingGateSlot",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});if(void 0!==u&&!(u instanceof n))throw new t("Bad heldColumn",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});if(void 0!==a&&void 0!==this.resizingGateSlot)throw new t("Holding AND resizing",{pos:e,heldGate:a,holdOffset:o,heldColumn:u,resizingGateSlot:s});this.pos=e,this.heldGate=a,this.holdOffset=o,this.heldColumn=u,this.resizingGateSlot=s}return $traceurRuntime.createClass(o,{paintCursor:function(e){void 0!==this.heldGate||void 0!==this.heldColumn?e.setDesiredCursor("move"):void 0!==this.resizingGateSlot&&e.setDesiredCursor("ns-resize")},isBusy:function(){return void 0!==this.heldGate||void 0!==this.heldColumn||void 0!==this.resizingGateSlot},hoverPoints:function(){return void 0===this.pos||this.isBusy()?[]:[this.pos]},isEqualTo:function(e){return this===e||e instanceof o&&a.CUSTOM_IS_EQUAL_TO_EQUALITY(this.pos,e.pos)&&a.CUSTOM_IS_EQUAL_TO_EQUALITY(this.holdOffset,e.holdOffset)&&a.CUSTOM_IS_EQUAL_TO_EQUALITY(this.heldGate,e.heldGate)&&a.CUSTOM_IS_EQUAL_TO_EQUALITY(this.heldColumn,e.heldColumn)&&a.CUSTOM_IS_EQUAL_TO_EQUALITY(this.resizingGateSlot,e.resizingGateSlot)},toString:function(){return"Hand("+e({pos:this.pos,heldGate:this.heldGate,holdOffset:this.holdOffset,heldColumn:this.heldColumn,resizingGateSlot:this.resizingGateSlot})},withPos:function(e){return new o(e,this.heldGate,this.holdOffset,this.heldColumn,this.resizingGateSlot)},withDrop:function(){return new o(this.pos,void 0,void 0,void 0,void 0)},withHeldGate:function(e,t){return new o(this.pos,e,t,void 0,void 0)},withHeldGateColumn:function(e,t){return new o(this.pos,void 0,t,e,void 0)},withResizeSlot:function(e,t){return new o(this.pos,void 0,t,void 0,e)},stableDuration:function(){return void 0!==this.heldGate?this.heldGate.stableDuration():void 0!==this.heldColumn?this.heldColumn.stableDuration():1/0}},{})}();return o.EMPTY=new o(void 0,void 0,void 0,void 0,void 0),{get Hand(){return o}}}),$traceurRuntime.registerModule("src/ui/menu.js",[],function(){"use strict";function e(e,n){var f,h;!function(){var e=document.getElementById("menu-button"),i=document.getElementById("close-menu-button"),a=document.getElementById("menu-overlay"),o=document.getElementById("menu-div");e.addEventListener("click",function(){return t.set(!0)}),n.subscribe(function(t){e.disabled=t}),a.addEventListener("click",function(){return t.set(!1)}),i.addEventListener("click",function(){return t.set(!1)}),document.addEventListener("keydown",function(e){27===e.keyCode&&t.set(!1)}),r.subscribe(function(e){o.style.display=e?"block":"none",e&&document.getElementById("export-link-copy-button").focus()})}();var g=document.getElementById("example-anchor-grover"),p=document.getElementById("example-anchor-teleport"),v=document.getElementById("example-anchor-delayed-eraser"),y=document.getElementById("example-addition"),b=document.getElementById("example-superdense-coding"),R=document.getElementById("example-symmetry-break"),w=document.getElementById("example-chsh-test"),M=document.getElementById("example-qft"),_=document.getElementById("example-anchor-shor"),x=!0,S=!1,T=void 0;try{for(var A=void 0,C=[[g,i],[_,m],[p,a],[v,o],[y,s],[b,l],[R,d],[w,u],[M,c]][Symbol.iterator]();!(x=(A=C.next()).done);x=!0)!function(){var r=A.value,n=(f=r[Symbol.iterator](),(h=f.next()).done?void 0:h.value),i=(h=f.next()).done?void 0:h.value,a=JSON.stringify(i);n.href="#circuit="+a,n.onclick=function(r){if(!(r.shiftKey||r.ctrlKey||r.altKey||1!==r.which))return e.commit(a),t.set(!1),!1}}()}catch(e){S=!0,T=e}finally{try{x||null==C.return||C.return()}finally{if(S)throw T}}}var t=new(0,$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Obs.js","src/ui/menu.js")).ObservableValue)(!0),r=t.observable().whenDifferent(),n=function(){return t.set(!1)},i={cols:[["X","X","X","X","X"],["H","H","H","H","H"],["Chance5"],["~vn6c"],["⊖","⊖","⊖","⊖","X"],["Chance5"],["~vn6c"],["⊖","⊖","⊖","⊖","X"],["Chance5"],["~vn6c"],["⊖","⊖","⊖","⊖","X"],["Chance5"],["~vn6c"],["⊖","⊖","⊖","⊖","X"],["Chance5"]],gates:[{id:"~vn6c",name:"Oracle",circuit:{cols:[["Z","•","◦","•","•"]]}}]},a={cols:[[1,"H"],[1,"•",1,1,"X"],["…","…",1,1,"…"],["…","…",1,1,"…"],["~87lj"],["Bloch"],["•","X"],["H"],["Measure","Measure"],[1,"•",1,1,"X"],["•",1,1,1,"Z"],[1,1,1,1,"Bloch"],[1,1,1,1,"~f7c0"]],gates:[{id:"~87lj",name:"message",circuit:{cols:[["e^-iYt"],["X^t"]]}},{id:"~f7c0",name:"received",matrix:"{{1,0},{0,1}}"}]},o={cols:[[1,"H"],[1,"•",1,1,"X"],[1,"~slits","QFT7"],[1,1,"Measure","Measure","Measure","Measure","Measure","Measure","Measure"],["…","…","Chance7"],["…","…"],["…","…"],["…","…"],["H"],["Measure"],["~choice"],["•","X^½"],[1,"Measure"],[1,"~result",1,1,1,"~flat"],["◦","◦","Chance7"],["◦","•","Chance7"],[1,1,1,1,1,"~waves"],["•","◦","Chance7"],["•","•","Chance7"]],gates:[{id:"~choice",name:"choice",matrix:"{{1,0},{0,1}}"},{id:"~result",name:"result",matrix:"{{1,0},{0,1}}"},{id:"~flat",name:"flat",matrix:"{{1,0},{0,1}}"},{id:"~waves",name:"waves",matrix:"{{1,0},{0,1}}"},{id:"~slits",name:"slits",matrix:"{{1,0},{0,1}}"}]},u={cols:[["H"],["◦",1,1,1,"X"],["X^-¼"],["…","…","…","…","…"],["~da85","~5s2n",1,"~5s2n","~ahov"],[1,"H",1,"H"],[1,"Measure",1,"Measure"],["X^½","•"],[1,1,1,"•","X^½"],["Measure",1,1,1,"Measure"],["…","…","…","…","…"],[1,"•","X","•"],["•",1,"X"],[1,1,"X",1,"•"],[1,1,"Chance"],[1,1,"~q6e"]],gates:[{id:"~da85",name:"Alice",matrix:"{{1,0},{0,1}}"},{id:"~ahov",name:"Bob",matrix:"{{1,0},{0,1}}"},{id:"~5s2n",name:"Referee",matrix:"{{1,0},{0,1}}"},{id:"~q6e",name:"Win?",matrix:"{{1,0},{0,1}}"}]},s={cols:[["Counting5",1,1,1,1,1,1,1,"X"],["Chance5",1,1,1,1,"Chance5"],["X","X","X","X","•","X","X","X","X","X"],[1,1,1,1,"•","X"],["Swap",1,1,1,"Swap","•"],[1,1,1,1,"•",1,"X"],[1,"Swap",1,1,"Swap",1,"•"],[1,1,1,1,"•",1,1,"X"],[1,1,"Swap",1,"Swap",1,1,"•"],[1,1,1,1,"•",1,1,1,"X"],[1,1,1,"Swap","Swap",1,1,1,"•"],[1,1,1,1,"•",1,1,1,1,"X"],[1,1,1,"Swap","Swap",1,1,1,"•"],[1,1,1,"•",1,1,1,1,"X"],[1,1,"Swap",1,"Swap",1,1,"•"],[1,1,"•",1,1,1,1,"X"],[1,"Swap",1,1,"Swap",1,"•"],[1,"•",1,1,1,1,"X"],["Swap",1,1,1,"Swap","•"],["•",1,1,1,1,"X"],["X","X","X","X","•","X","X","X","X","X"],["Chance5",1,1,1,1,"Chance5"]]},c={cols:[["Counting8"],["Chance8"],["…","…","…","…","…","…","…","…"],["Swap",1,1,1,1,1,1,"Swap"],[1,"Swap",1,1,1,1,"Swap"],[1,1,"Swap",1,1,"Swap"],[1,1,1,"Swap","Swap"],["H"],["Z^½","•"],[1,"H"],["Z^¼","Z^½","•"],[1,1,"H"],["Z^⅛","Z^¼","Z^½","•"],[1,1,1,"H"],["Z^⅟₁₆","Z^⅛","Z^¼","Z^½","•"],[1,1,1,1,"H"],["Z^⅟₃₂","Z^⅟₁₆","Z^⅛","Z^¼","Z^½","•"],[1,1,1,1,1,"H"],["Z^⅟₆₄","Z^⅟₃₂","Z^⅟₁₆","Z^⅛","Z^¼","Z^½","•"],[1,1,1,1,1,1,"H"],["Z^⅟₁₂₈","Z^⅟₆₄","Z^⅟₃₂","Z^⅟₁₆","Z^⅛","Z^¼","Z^½","•"],[1,1,1,1,1,1,1,"H"]]},l={cols:[[1,1,"H"],[1,1,"•",1,1,1,"X"],["…","…","…","…","…","…","…"],["Counting2"],["Measure","Measure"],["~msg"],["Chance","Chance"],["~enc"],[1,"•","X"],["•",1,"Z"],[1,1,1,"~send"],[1,1,"Swap",1,1,"Swap"],[1,1,1,1,1,"~dec"],[1,1,1,1,1,"•","X"],[1,1,1,1,1,"H"],[1,1,1,1,1,"Measure","Measure"],[1,1,1,1,1,"~msg"],[1,1,1,1,1,"Chance","Chance"]],gates:[{id:"~msg",name:"message",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~enc",name:"encode",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~send",name:"send",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~dec",name:"decode",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"}]},d={cols:[["~tpqg",1,"~r2ku"],["…","…","…","…"],["H"],[1,1,"H"],["•","X"],[1,1,"•","X"],[1,"Swap",1,"Swap"],["•","X"],[1,1,"•","X"],["X^½","◦"],[1,1,"X^½","◦"],[1,"X^½"],[1,1,1,"X^½"],["Measure","Measure","Measure","Measure"],[1,"~57au"],["•",1,"Chance"],[1,"•",1,"Chance"],["◦",1,"Chance"],[1,"◦",1,"Chance"]],gates:[{id:"~tpqg",name:"Alice^1",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~r2ku",name:"Alice^2",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~57au",name:"disagree",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"}]},m={cols:[[1,1,1,1,1,1,1,1,1,1,"~input",1,1,1,"~guess"],[1,1,1,1,1,1,1,1,1,1,{id:"setR",arg:55},1,1,1,{id:"setB",arg:26}],[],["H","H","H","H","H","H","H","H","H","H","X"],["inputA10",1,1,1,1,1,1,1,1,1,"*BToAmodR6"],["QFT†10"],[1,1,1,1,"~out"],["Chance10"]],gates:[{id:"~guess",name:"guess:",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~input",name:"input:",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"},{id:"~out",name:"out:",matrix:"{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}"}]};return{get initMenu(){return e},get obsMenuIsShowing(){return r},get closeMenu(){return n}}}),$traceurRuntime.registerModule("src/ui/sim.js",[],function(){"use strict";function e(e){if(void 0!==i&&i.circuitDefinition.isEqualTo(e))return i.withTime(n());i=void 0;var t=r.fromCircuitAtTime(e,n());return e.stableDuration()===1/0&&(i=t),t}$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/ui/sim.js")).CircuitDefinition;var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/sim.js")).Config,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitStats.js","src/ui/sim.js")).CircuitStats,n=function(){var e=0,r=performance.now();return function(){var n=performance.now(),i=(n-r)/t.CYCLE_DURATION_MS;return e+=i,e%=1,r=n,e}}(),i=void 0;return{get simulate(){return e},get getCircuitCycleTime(){return n}}}),$traceurRuntime.registerModule("src/ui/title.js",[],function(){"use strict";function e(e){var n=function(e){try{var n=r(e);if(!n.isEmpty())return"Quirk: "+n.readableHash()}catch(e){}return t.EMPTY_CIRCUIT_TITLE};e.latestActiveCommit().subscribe(function(e){setTimeout(function(){document.title=n(e)},0)})}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/title.js")).Config,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/ui/title.js")).fromJsonText_CircuitDefinition;return{get initTitleSync(){return e}}}),$traceurRuntime.registerModule("src/ui/undo.js",[],function(){"use strict";function e(e,t){var r=[document.getElementById("gate-forge-div"),document.getElementById("export-div")],n=document.getElementById("undo-button"),i=document.getElementById("redo-button");e.latestActiveCommit().zipLatest(t,function(e,t){return t}).subscribe(function(t){n.disabled=e.isAtBeginningOfHistory()||t,i.disabled=e.isAtEndOfHistory()||t}),n.addEventListener("click",function(){return e.undo()}),i.addEventListener("click",function(){return e.redo()}),document.addEventListener("keydown",function(t){var n=!0,i=!1,a=void 0;try{for(var o=void 0,u=r[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;if("NONE"!==s.style.display&&"none"!==s.style.display)return}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}var c=90===t.keyCode&&t.ctrlKey&&!t.shiftKey&&!t.altKey&&!t.metaKey,l=90===t.keyCode&&t.ctrlKey&&t.shiftKey&&!t.altKey&&!t.metaKey,d=89===t.keyCode&&t.ctrlKey&&!t.shiftKey&&!t.altKey&&!t.metaKey;c&&(e.undo(),t.preventDefault()),(l||d)&&(e.redo(),t.preventDefault())})}return{get initUndoRedo(){return e}}}),$traceurRuntime.registerModule("src/ui/url.js",[],function(){"use strict";function e(e){return-1===e.indexOf("%")&&-1===e.indexOf("&")||(e=encodeURIComponent(e)),"#"+i.URL_CIRCUIT_PARAM_KEY+"="+e}function t(t){var o=function(){var e=document.location.hash.substr(1),t=new Map;if(""!==e){var r=!0,n=!1,i=void 0;try{for(var a=void 0,o=e.split("&")[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value,s=u.indexOf("=");if(-1!==s){var c=u.substring(0,s),l=decodeURIComponent(u.substring(s+1));t.set(c,l)}}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}return t},c=new a,l=function(){try{c.currentStateIsMemorableButUnknown();var a=o();if(!a.has(i.URL_CIRCUIT_PARAM_KEY)){var l=document.DEFAULT_CIRCUIT||JSON.stringify(s.toJson(n.EMPTY));a.set(i.URL_CIRCUIT_PARAM_KEY,l)}var d=a.get(i.URL_CIRCUIT_PARAM_KEY);c.currentStateIsMemorableAndEqualTo(d);var m=u(d),f=JSON.stringify(s.toJson(m));if(t.clear(f),m.isEmpty()&&1===a.size)c.currentStateIsNotMemorable();else{var h=e(d);c.stateChange(d,h)}}catch(e){r("Defaulted to an empty circuit. Failed to understand circuit from URL.",{document_location_hash:document.location.hash},e)}};window.addEventListener("popstate",l),l(),t.latestActiveCommit().whenDifferent().skip(1).subscribe(function(t){c.stateChange(t,e(t))})}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/fallback.js","src/ui/url.js")).notifyAboutRecoveryFromUnexpectedError,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/CircuitDefinition.js","src/ui/url.js")).CircuitDefinition,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/ui/url.js")).Config,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/browser/HistoryPusher.js","src/ui/url.js")).HistoryPusher,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/circuit/Serializer.js","src/ui/url.js")),u=o.fromJsonText_CircuitDefinition,s=o.Serializer;return{get initUrlCircuitSync(){return t}}}),$traceurRuntime.registerModule("src/webgl/ShaderCoders_Base.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/ShaderCoders_Base.js")).WglArg,t=function(){return $traceurRuntime.createClass(function(e,t,r){this.code=e,this.libs=t,this.argsFor=r},{},{})}(),r=function(){return $traceurRuntime.createClass(function(e,t,r,n,i,a,o){this.inputPartGetter=e,this.outputPart=t,this.powerSizeOverhead=r,this.pixelType=n,this.dataToPixels=i,this.pixelsToData=a,this.needRearrangingToBeInVec4Format=o},{arrayPowerSizeOfTexture:function(e){return e.sizePower()-this.powerSizeOverhead}},{})}(),n=function(){return $traceurRuntime.createClass(function(e,t,r,n){this.bool=e,this.float=t,this.vec2=r,this.vec4=n},{},{})}(),i=new t("\n ///////////// BOOL_OUTPUT_AS_FLOAT ////////////\n bool outputFor(float k);\n\n uniform vec2 _gen_output_size;\n uniform float _gen_secret_half;\n\n float len_output() {\n return _gen_output_size.x * _gen_output_size.y;\n }\n\n void main() {\n vec2 xy = gl_FragCoord.xy - vec2(_gen_secret_half, _gen_secret_half);\n float k = xy.y * _gen_output_size.x + xy.x;\n gl_FragColor = vec4(float(outputFor(k)), 0.0, 0.0, 0.0);\n }",[],function(t){return[e.vec2("_gen_output_size",t.width,t.height),e.float("_gen_secret_half",.5)]}),a=new r(function(r){var n="_gen_"+r;return new t("\n ///////////// boolInput("+r+") ////////////\n uniform sampler2D "+n+"_tex;\n uniform vec2 "+n+"_size;\n\n float read_"+r+"(float k) {\n vec2 uv = vec2(mod(k, "+n+"_size.x) + 0.5,\n floor(k / "+n+"_size.x) + 0.5) / "+n+"_size;\n return float(texture2D("+n+"_tex, uv).x == 1.0);\n }\n\n float len_"+r+"() {\n return "+n+"_size.x * "+n+"_size.y * 4.0;\n }",[],function(t){return[e.texture(n+"_tex",t),e.vec2(n+"_size",t.width,t.height)]})},i,0,WebGLRenderingContext.UNSIGNED_BYTE,function(e){return e},function(e){return e},!1);return{get SingleTypeCoder(){return r},get ShaderCoder(){return n},get ShaderPart(){return t},get BOOL_TYPE_CODER(){return a}}}),$traceurRuntime.registerModule("src/webgl/ShaderCoders_intoBytes.js",[],function(){"use strict";function e(e){if(e instanceof Float64Array)return new Uint8Array(new Float32Array(e).buffer,0,e.length<<2);if(e instanceof Float32Array)return new Uint8Array(e.buffer,0,e.length<<2);throw new i("Not a Float32Array or Float64Array",{type:void 0===e?"undefined":$traceurRuntime.typeof(e),floats:e})}function t(e){if(!(e instanceof Uint8Array))throw new i("Not a Uint8Array",{type:void 0===e?"undefined":$traceurRuntime.typeof(e),bytes:e});return new Float32Array(e.buffer,0,e.length>>2)}function r(e,t){var r=["float","vec2","vec3","vec4"][e-1],n="_gen_"+t;return new s("\n ///////////// makeByteCoderInput("+e+", "+t+") ////////////\n uniform sampler2D "+n+"_tex;\n uniform vec2 "+n+"_size;\n\n "+r+" read_"+t+"(float k) {\n k *= "+e+".0;\n vec2 uv = vec2(mod(k, "+n+"_size.x) + 0.5,\n floor(k / "+n+"_size.x) + 0.5) / "+n+"_size;\n\n "+o.range(e).map(function(e){return"\n vec2 uv"+e+" = uv + vec2("+e+".0 / "+n+"_size.x, 0.0);\n vec4 bytes"+e+" = texture2D("+n+"_tex, uv"+e+");"}).join("")+"\n\n return "+r+"("+o.range(e).map(function(e){return"\n _gen_unpackBytesIntoFloat(bytes"+e+")"}).join(",")+");\n }\n\n float len_"+t+"() {\n return "+n+"_size.x * "+n+"_size.y / "+e+".0;\n }",[d],function(e){if(e.pixelType!==WebGLRenderingContext.UNSIGNED_BYTE)throw new i("vec2Input_Byte requires byte texture",{name:t,texture:e});return[a.texture(n+"_tex",e),a.vec2(n+"_size",e.width,e.height)]})}function n(e){var t=["float","vec2","vec3","vec4"][e-1];return new s("\n ///////////// makeByteCoderOutput"+e+" ////////////\n "+t+" outputFor(float k);\n\n uniform vec2 _gen_output_size;\n uniform float _gen_secret_half;\n\n float len_output() {\n return _gen_output_size.x * _gen_output_size.y / "+e+".0;\n }\n\n void main() {\n vec2 xy = gl_FragCoord.xy - vec2(_gen_secret_half, _gen_secret_half);\n float k = xy.y * _gen_output_size.x + xy.x;\n float r = mod(k, "+e+".0);\n "+(1===e?"float component = outputFor(k);":t+" result = outputFor(floor(k / "+e+".0));\n "+t+" picker = "+t+"("+o.range(e).map(function(e){return"float(r == "+e+".0)"}).join(", ")+");\n float component = dot(result, picker);")+"\n gl_FragColor = _gen_packFloatIntoBytes(component);\n }",[l],function(e){return[a.vec2("_gen_output_size",e.width,e.height),a.float("_gen_secret_half",.5)]})}var i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/ShaderCoders_intoBytes.js")).DetailedError,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/ShaderCoders_intoBytes.js")).WglArg,o=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/webgl/ShaderCoders_intoBytes.js")).Seq,u=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders_Base.js","src/webgl/ShaderCoders_intoBytes.js")),s=u.ShaderPart,c=u.SingleTypeCoder,l="\n //////////// PACK_FLOAT_INTO_BYTES /////////////\n vec4 _gen_packFloatIntoBytes(float val) {\n if (val == 0.0) {\n // If log2(0) returns -Infinity, then the logic below would work out just right and this IF block\n // wouldn't be needed. Unfortunately, log2(0) isn't guaranteed to do that (it's undefined by the spec).\n return vec4(0.0, 0.0, 0.0, 0.0);\n }\n\n float mag = abs(val);\n float exponent = floor(log2(mag));\n // Correct log2 approximation errors.\n exponent += float(exp2(exponent) <= mag / 2.0);\n exponent -= float(exp2(exponent) > mag);\n\n float mantissa;\n if (exponent > 100.0) {\n // Not sure why this needs to be done in two steps for the largest float to work. Best guess is the\n // optimizer is rewriting '/ exp2(e)' into '* exp2(-e)', but exp2(-128.0) is too small to represent.\n mantissa = mag / 1024.0 / exp2(exponent - 10.0) - 1.0;\n } else {\n mantissa = mag / float(exp2(exponent)) - 1.0;\n }\n\n exponent += 127.0;\n float a = float(val < 0.0) * 128.0 + floor(exponent / 2.0);\n mantissa *= 128.0;\n float b = mod(exponent, 2.0) * 128.0 + floor(mantissa);\n mantissa -= floor(mantissa);\n mantissa *= 256.0;\n float c = floor(mantissa);\n mantissa -= c;\n mantissa *= 256.0;\n float d = floor(mantissa);\n\n return vec4(d, c, b, a) / 255.0;\n }",d="\n //////////// UNPACK_BYTES_INTO_FLOAT_CODE /////////////\n float _gen_unpackBytesIntoFloat(vec4 v) {\n float d = floor(v.r * 255.0 + 0.5);\n float c = floor(v.g * 255.0 + 0.5);\n float b = floor(v.b * 255.0 + 0.5);\n float a = floor(v.a * 255.0 + 0.5);\n\n float sign = floor(a / 128.0);\n sign = 1.0 - sign * 2.0;\n\n float exponent = mod(a, 128.0) * 2.0 + floor(b / 128.0) - 127.0;\n float mantissa = float(exponent > -127.0)\n + mod(b, 128.0) / 128.0\n + c / 32768.0\n + d / 8388608.0;\n return sign * mantissa * exp2(exponent);\n }",m=new(0,u.ShaderCoder)(u.BOOL_TYPE_CODER,new c(function(e){return r(1,e)},n(1),0,WebGLRenderingContext.UNSIGNED_BYTE,e,t,!1),new c(function(e){return r(2,e)},n(2),1,WebGLRenderingContext.UNSIGNED_BYTE,e,t,!1),new c(function(e){return r(4,e)},n(4),2,WebGLRenderingContext.UNSIGNED_BYTE,e,t,!1));return{get SHADER_CODER_BYTES(){return m},get floatsAsBytes(){return e},get bytesAsFloats(){return t},get UNPACK_BYTES_INTO_FLOAT_CODE(){return d},get PACK_FLOAT_INTO_BYTES_CODE(){return l}}}),$traceurRuntime.registerModule("src/webgl/ShaderCoders_intoFloats.js",[],function(){"use strict";function e(e,t){var n="_gen_"+t;return new i("\n ///////////// makeFloatCoderInput("+e+", "+t+") ////////////\n uniform sampler2D "+n+"_tex;\n uniform vec2 "+n+"_size;\n\n "+["float","vec2","vec3","vec4"][e-1]+" read_"+t+"(float k) {\n vec2 uv = vec2(mod(k, "+n+"_size.x) + 0.5,\n floor(k / "+n+"_size.x) + 0.5) / "+n+"_size;\n return texture2D("+n+"_tex, uv)."+"xyzw".substring(0,e)+";\n }\n\n float len_"+t+"() {\n return "+n+"_size.x * "+n+"_size.y;\n }",[],function(i){if(i.pixelType!==WebGLRenderingContext.FLOAT)throw new r("vecInput"+e+"_Float requires float texture",{name:t,texture:i});return[s.texture(n+"_tex",i),s.vec2(n+"_size",i.width,i.height)]})}function t(e){var t=["float","vec2","vec3","vec4"][e-1];return new i("\n ///////////// makeFloatCoderOutput"+e+" ////////////\n "+t+" outputFor(float k);\n\n uniform vec2 _gen_output_size;\n uniform float _gen_secret_half;\n\n float len_output() {\n return _gen_output_size.x * _gen_output_size.y;\n }\n\n void main() {\n vec2 xy = gl_FragCoord.xy - vec2(_gen_secret_half, _gen_secret_half);\n float k = xy.y * _gen_output_size.x + xy.x;\n\n "+t+" v = outputFor(k);\n\n gl_FragColor = "+["vec4(v, 0.0, 0.0, 0.0)","vec4(v.x, v.y, 0.0, 0.0)","vec4(v.x, v.y, v.z, 0.0)","v"][e-1]+";\n }",[],function(e){return[s.vec2("_gen_output_size",e.width,e.height),s.float("_gen_secret_half",.5)]})}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/ShaderCoders_intoFloats.js")).DetailedError,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders_Base.js","src/webgl/ShaderCoders_intoFloats.js")),i=n.ShaderPart,a=n.SingleTypeCoder,o=n.ShaderCoder,u=n.BOOL_TYPE_CODER,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/ShaderCoders_intoFloats.js")).WglArg,c=new o(u,new a(function(t){return e(1,t)},t(1),0,WebGLRenderingContext.FLOAT,function(e){for(var t=new Float32Array(e.length<<2),r=0;r<e.length;r++)t[4*r]=e[r];return t},function(e){for(var t=new Float32Array(e.length>>2),r=0;r<t.length;r++)t[r]=e[4*r];return t},!0),new a(function(t){return e(2,t)},t(2),0,WebGLRenderingContext.FLOAT,function(e){for(var t=new Float32Array(e.length<<1),r=0;2*r<e.length;r++)t[4*r]=e[2*r],t[4*r+1]=e[2*r+1];return t},function(e){for(var t=new Float32Array(e.length>>1),r=0;2*r<t.length;r++)t[2*r]=e[4*r],t[2*r+1]=e[4*r+1];return t},!0),new a(function(t){return e(4,t)},t(4),0,WebGLRenderingContext.FLOAT,function(e){return e},function(e){return e},!1));return{get SHADER_CODER_FLOATS(){return c}}}),$traceurRuntime.registerModule("src/webgl/ShaderCoders.js",[],function(){"use strict";function e(e,t){var r=e.map(function(e){return e instanceof p?new b(function(t){return e},"fixed"):e});return new l(function(){var e=new Set,n=!0,i=!1,a=void 0;try{for(var o=void 0,u=r[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value,c=!0,l=!1,d=void 0;try{for(var m=void 0,f=s.toConcretePart().libs[Symbol.iterator]();!(c=(m=f.next()).done);c=!0){var h=m.value;e.add(h)}}catch(e){l=!0,d=e}finally{try{c||null==f.return||f.return()}finally{if(l)throw d}}}}catch(e){i=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw a}}var g=$traceurRuntime.spread(e,r.map(function(e){return e.toConcretePart().code})).join(""),p="\n//////// body ////////\n"+t+"\n",v=g.indexOf("void main()");return-1!==v?g.substring(0,v)+p+g.substring(v):g+p})}function t(t,n,i){var a=e($traceurRuntime.spread(t,[n]),i);return function(){for(var e,i,o=[],u=0;u<arguments.length;u++)o[u]=arguments[u];for(var s=[],c=0;c<t.length;c++)(e=s).push.apply(e,$traceurRuntime.spread(t[c].toConcretePart().argsFor(o[c])));return(i=s).push.apply(i,$traceurRuntime.spread(o.slice(t.length))),r(a,n.toConcretePart(),s)}}function r(e,t,r){return new g(function(n){var i;return(i=e).withArgs.apply(i,$traceurRuntime.spread(r,t.argsFor(n))).renderTo(n)})}function n(){return M}function i(){return _}function a(e){try{m().invalidateExistingResources()}catch(e){}M=e,_=e}function o(){var e=new d(1,1,WebGLRenderingContext.FLOAT),t=new l("void main() { gl_FragColor = vec4(2.0, 3.5, 7.0, -7654321.0); }");try{t.withArgs().renderTo(e);var r=e.readPixels(!1);return r instanceof Float32Array&&4===r.length&&2===r[0]&&3.5===r[1]&&7===r[2]&&-7654321===r[3]}catch(e){return console.warn(e),!1}finally{e.ensureDeinitialized(),t.ensureDeinitialized()}}function u(){var e=new d(1,1,WebGLRenderingContext.FLOAT),t=new d(1,1,WebGLRenderingContext.UNSIGNED_BYTE),r=new l("void main() { gl_FragColor = vec4(1.1, 3.0, 5.0, -7654321.0); }"),n=new l("uniform sampler2D t; void main() {\n vec4 v = texture2D(t, gl_FragCoord.xy);\n if (v == vec4(2.0, 3.0, 5.0, -7654321.0)) { // Testing that expected precision is present.\n gl_FragColor = vec4(2.0, 3.0, 5.0, 254.0) / 255.0;\n } else {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n }");try{r.withArgs().renderTo(e),n.withArgs(c.texture("t",e)).renderTo(t);var i=t.readPixels(!1);return i instanceof Uint8Array&&4===i.length&&2===i[0]&&3===i[1]&&5===i[2]&&254===i[3]}catch(e){return console.warn(e),!1}finally{e.ensureDeinitialized(),t.ensureDeinitialized(),r.ensureDeinitialized(),n.ensureDeinitialized()}}function s(){return void 0===x&&(x=o()),x}var c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/ShaderCoders.js")).WglArg,l=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglShader.js","src/webgl/ShaderCoders.js")).WglShader,d=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexture.js","src/webgl/ShaderCoders.js")).WglTexture,m=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglContext.js","src/webgl/ShaderCoders.js")).initializedWglContext,f=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/webgl/ShaderCoders.js")),h=f.provideWorkingShaderCoderToWglConfiguredShader,g=f.WglConfiguredShader,p=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders_Base.js","src/webgl/ShaderCoders.js")).ShaderPart,v=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders_intoBytes.js","src/webgl/ShaderCoders.js")).SHADER_CODER_BYTES,y=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders_intoFloats.js","src/webgl/ShaderCoders.js")).SHADER_CODER_FLOATS,b=function(){return $traceurRuntime.createClass(function(e,t){this._partMaker=e,this.description=t},{toConcretePart:function(){var e=arguments[0];return this._partMaker(e||n())},toString:function(){return"ShaderPartDescription("+this.description+")"}},{})}(),R=function(){return $traceurRuntime.createClass(function(){},{},{bool:function(e){return new b(function(t){return t.bool.inputPartGetter(e)},"Inputs.bool("+e+")")},float:function(e){return new b(function(t){return t.float.inputPartGetter(e)},"Inputs.float("+e+")")},vec2:function(e){return new b(function(t){return t.vec2.inputPartGetter(e)},"Inputs.vec2("+e+")")},vec4:function(e){return new b(function(t){return t.vec4.inputPartGetter(e)},"Inputs.vec4("+e+")")}})}(),w=function(){return $traceurRuntime.createClass(function(){},{},{bool:function(){return new b(function(e){return e.bool.outputPart},"Outputs.bool()")},float:function(){return new b(function(e){return e.float.outputPart},"Outputs.float()")},vec2:function(){return new b(function(e){return e.vec2.outputPart},"Outputs.vec2()")},vec4:function(){return new b(function(e){return e.vec4.outputPart},"Outputs.vec4()")},vec4WithOutputCoder:function(){return new b(function(e){return i().vec4.outputPart},"Outputs.vec4WithOutputCoder()")}})}(),M=y,_=v,x=void 0;return o()?(M=y,_=y):u()?(console.warn("Wrote but failed to read a floating point texture. Falling back to float-as-byte output coding."),M=y,_=v):(console.warn("Failed to write a floating point texture. Falling back to float-as-byte coding everywhere."),M=v,_=v),h(n),{get combinedShaderPartsWithCode(){return e},get shaderWithOutputPartAndArgs(){return r},get currentShaderCoder(){return n},get makePseudoShaderWithInputsAndOutputAndCode(){return t},get changeShaderCoder(){return a},get Inputs(){return R},get Outputs(){return w},get outputShaderCoder(){return i},get canTestFloatShaders(){return s}}}),$traceurRuntime.registerModule("src/webgl/Shaders.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/Shaders.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/Shaders.js")).WglArg,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglContext.js","src/webgl/Shaders.js")).initializedWglContext,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglShader.js","src/webgl/Shaders.js")).WglShader,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/webgl/Shaders.js")).WglConfiguredShader,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/webgl/Shaders.js")),o=a.currentShaderCoder,u=a.Inputs,s=a.Outputs,c=a.makePseudoShaderWithInputsAndOutputAndCode,l=function(){return $traceurRuntime.createClass(function(){},{},{})}();l.color=function(e,r,n,i){return d.withArgs(t.vec4("color",e,r,n,i))};var d=new n("\n uniform vec4 color;\n void main() {\n gl_FragColor = color;\n }");l.passthrough=function(r){return new i(function(n){if(n.width!==r.width||n.height!==r.height||n.pixelType!==r.pixelType)throw new e("Expected same-shaped textures.",{inp:r,dst:n});m.withArgs(t.vec2("textureSize",r.width,r.height),t.texture("dataTexture",r)).renderTo(n)})};var m=new n("\n uniform vec2 textureSize;\n uniform sampler2D dataTexture;\n void main() {\n gl_FragColor = texture2D(dataTexture, gl_FragCoord.xy / textureSize.xy);\n }");return l.data=function(n){return new i(function(i){var a,o,u=(a=[i.width,i.height][Symbol.iterator](),(o=a.next()).done?void 0:o.value),s=(o=a.next()).done?void 0:o.value;if(n.length!==u*s*4)throw new e("rgbaData.length isn't w * h * 4",{w:u,h:s,len:n.length,rgbaData:n});var c=WebGLRenderingContext,l=r().gl,d=l.createTexture();try{l.bindTexture(WebGLRenderingContext.TEXTURE_2D,d),l.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST),l.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),l.texImage2D(c.TEXTURE_2D,0,c.RGBA,u,s,0,c.RGBA,n instanceof Uint8Array?c.UNSIGNED_BYTE:c.FLOAT,n),m.withArgs(t.vec2("textureSize",u,s),t.webGlTexture("dataTexture",d)).renderTo(i)}finally{l.deleteTexture(d)}})},l.vec2Data=function(e){return l.data(o().vec2.dataToPixels(e))},l.vec4Data=function(e){return l.data(o().vec4.dataToPixels(e))},l.packFloatIntoVec4=c([u.float("input")],s.vec4(),"vec4 outputFor(float k) {\n return vec4(\n read_input(k*4.0),\n read_input(k*4.0 + 1.0),\n read_input(k*4.0 + 2.0),\n read_input(k*4.0 + 3.0));\n }"),l.packVec2IntoVec4=c([u.vec2("input")],s.vec4(),"vec4 outputFor(float k) { return vec4(read_input(k*2.0), read_input(k*2.0 + 1.0)); }"),l.sumFoldFloat=c([u.float("input")],s.float(),"float outputFor(float k) {\n return read_input(k) + read_input(k + len_output());\n }"),l.sumFoldVec2=c([u.vec2("input")],s.vec2(),"vec2 outputFor(float k) {\n return read_input(k) + read_input(k + len_output());\n }"),l.sumFoldVec4=c([u.vec4("input")],s.vec4(),"vec4 outputFor(float k) {\n return read_input(k) + read_input(k + len_output());\n }"),l.convertVec4CodingForOutput=c([u.vec4("input")],s.vec4WithOutputCoder(),"vec4 outputFor(float k) { return read_input(k); }"),{get Shaders(){return l}}}),$traceurRuntime.registerModule("src/webgl/WglArg.js",[],function(){"use strict";var e=function(){function e(e,t,r){this.type=e,this.name=t,this.value=r}return $traceurRuntime.createClass(e,{toString:function(){return this.type+" "+this.name+" = "+JSON.stringify(this.value)}},{bool:function(t,r){return new e(e.BOOL_TYPE,t,r)},float:function(t,r){return new e(e.FLOAT_TYPE,t,r)},int:function(t,r){return new e(e.INT_TYPE,t,r)},vec2:function(t,r,n){return new e(e.VEC2_TYPE,t,[r,n])},float_array:function(t,r){return r instanceof Float64Array&&(r=new Float32Array(r)),new e(e.FLOAT_ARRAY_TYPE,t,r)},vec2_array:function(t,r){return r instanceof Float64Array&&(r=new Float32Array(r)),new e(e.VEC2_ARRAY_TYPE,t,r)},vec4_array:function(t,r){return r instanceof Float64Array&&(r=new Float32Array(r)),new e(e.VEC4_ARRAY_TYPE,t,r)},mat4_array:function(t,r){return r instanceof Float64Array&&(r=new Float32Array(r)),new e(e.MAT4_ARRAY_TYPE,t,r)},vec4:function(t,r,n,i,a){return new e(e.VEC4_TYPE,t,[r,n,i,a])},mat4:function(t,r){return new e(e.MAT4_TYPE,t,r)},texture:function(t,r){return new e(e.WGL_TEXTURE_TYPE,t,r)},webGlTexture:function(t,r){return new e(e.WEB_GL_TEXTURE_TYPE,t,r)}})}();return e.BOOL_TYPE="bool",e.FLOAT_TYPE="float",e.INT_TYPE="int",e.VEC2_TYPE="vec2",e.FLOAT_ARRAY_TYPE="float[]",e.VEC2_ARRAY_TYPE="vec2[]",e.VEC4_ARRAY_TYPE="vec4[]",e.MAT4_ARRAY_TYPE="mat4[]",e.VEC4_TYPE="vec4",e.MAT4_TYPE="mat4",e.WGL_TEXTURE_TYPE="wgl_texture",e.WEB_GL_TEXTURE_TYPE="web_gl_texture",e.INPUT_ACTION_MAP=new Map([[e.BOOL_TYPE,function(e,t,r){return e.gl.uniform1f(t,r?1:0)}],[e.INT_TYPE,function(e,t,r){return e.gl.uniform1i(t,r)}],[e.FLOAT_TYPE,function(e,t,r){return e.gl.uniform1f(t,r)}],[e.VEC2_TYPE,function(e,t,r){var n,i,a=(n=r[Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value;return e.gl.uniform2f(t,a,o)}],[e.FLOAT_ARRAY_TYPE,function(e,t,r){return e.gl.uniform1fv(t,r)}],[e.VEC2_ARRAY_TYPE,function(e,t,r){return e.gl.uniform2fv(t,r)}],[e.VEC4_ARRAY_TYPE,function(e,t,r){return e.gl.uniform4fv(t,r)}],[e.MAT4_ARRAY_TYPE,function(e,t,r){return e.gl.uniformMatrix4fv(t,!1,r)}],[e.VEC4_TYPE,function(e,t,r){var n,i,a=(n=r[Symbol.iterator](),(i=n.next()).done?void 0:i.value),o=(i=n.next()).done?void 0:i.value,u=(i=n.next()).done?void 0:i.value,s=(i=n.next()).done?void 0:i.value;return e.gl.uniform4f(t,a,o,u,s)}],[e.MAT4_TYPE,function(e,t,r){return e.gl.uniformMatrix4fv(t,!1,r)}],[e.WGL_TEXTURE_TYPE,function(e,t,r,n){var i=n.coopTextureUnit++;if(i>=e.maxTextureUnits)throw new Error("Uniform texture argument uses texture unit "+i+" but max is "+e.maxTextureUnits+".");if(r.width>e.maxTextureSize||r.height>e.maxTextureSize)throw new Error("Uniform texture argument is "+r.width+"x"+r.height+", but max texture diameter is "+e.maxTextureSize+".");var a=e.gl;a.uniform1i(t,i),a.activeTexture(WebGLRenderingContext.TEXTURE0+i),a.bindTexture(WebGLRenderingContext.TEXTURE_2D,r.initializedTexture())}],[e.WEB_GL_TEXTURE_TYPE,function(e,t,r,n){var i=n.coopTextureUnit++;if(i>=e.maxTextureUnits)throw new Error("Uniform texture argument uses texture unit "+i+" but max is "+e.maxTextureUnits+".");var a=e.gl;a.uniform1i(t,i),a.activeTexture(WebGLRenderingContext.TEXTURE0+i),a.bindTexture(WebGLRenderingContext.TEXTURE_2D,r)}]]),{get WglArg(){return e}}}),$traceurRuntime.registerModule("src/webgl/WglConfiguredShader.js",[],function(){"use strict";function e(e){i=e}function t(e){r=e}var r,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/math/Matrix.js","src/webgl/WglConfiguredShader.js")).Matrix,i=($traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexture.js","src/webgl/WglConfiguredShader.js")).WglTexture,void 0),a=function(){function e(e){this.renderToFunc=e}return $traceurRuntime.createClass(e,{renderTo:function(t){if(this.renderToFunc(t)instanceof e)throw new Error("Returned a WglConfiguredShader instead of calling renderTo on it.")},_renderToElseDealloc:function(e){var t=!1;try{this.renderTo(e),t=!0}finally{t||e.deallocByDepositingInPool("_renderToElseDealloc")}},_renderReadDealloc:function(e){try{return this.renderTo(e),e.readPixels()}finally{e.deallocByDepositingInPool()}},toRawByteTexture:function(e){var t=r.takeRawByteTex(e);return this._renderToElseDealloc(t),t},toRawFloatTexture:function(e){var t=r.takeRawFloatTex(e);return this._renderToElseDealloc(t),t},readRawFloatOutputs:function(e){return this._renderReadDealloc(r.takeRawFloatTex(e))},readRawByteOutputs:function(e){return this._renderReadDealloc(r.takeRawByteTex(e))},readBoolOutputs:function(e){for(var t=this._renderReadDealloc(r.takeBoolTex(e)),n=new Uint8Array(t.length>>2),i=0;i<n.length;i++)n[i]=1&t[i<<2];return n},readVecFloatOutputs:function(e){return i().float.pixelsToData(this._renderReadDealloc(r.takeVecFloatTex(e)))},readVec2Outputs:function(e){return i().vec2.pixelsToData(this._renderReadDealloc(r.takeVec2Tex(e)))},readVec2OutputsAsKet:function(e){return new n(1,1<<e,this.readVec2Outputs(e))},readVec4Outputs:function(e){return i().vec4.pixelsToData(this._renderReadDealloc(r.takeVec4Tex(e)))},toVecFloatTexture:function(e){var t=r.takeVecFloatTex(e);return this._renderToElseDealloc(t),t},toVec2Texture:function(e){var t=r.takeVec2Tex(e);return this._renderToElseDealloc(t),t},toVec4Texture:function(e){var t=r.takeVec4Tex(e);return this._renderToElseDealloc(t),t},toBoolTexture:function(e){var t=r.takeBoolTex(e);return this._renderToElseDealloc(t),t}},{})}();return{get WglConfiguredShader(){return a},get provideWorkingShaderCoderToWglConfiguredShader(){return e},get provideWglTexturePoolToWglConfiguredShader(){return t}}}),$traceurRuntime.registerModule("src/webgl/WglContext.js",[],function(){"use strict";function e(){return void 0===a&&(a=new i(r,n)),a}var t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/issues.js","src/webgl/WglContext.js")),r=t.canvasCreatedForTesting,n=t.webglContextCreatedForTesting,i=function(){return $traceurRuntime.createClass(function(){var e=arguments[0],t=arguments[1],r=this;if(void 0===e&&(e=document.createElement("canvas"),t=void 0),void 0===t&&(t=e.getContext("webgl")||e.getContext("experimental-webgl")),this.canvas=e,this.gl=t,null===this.gl)throw new Error("Error creating WebGL context.");void 0===this.gl.getExtension("OES_texture_float")&&console.warn("OES_texture_float webgl extension not present."),void 0===this.gl.getExtension("WEBGL_color_buffer_float")&&console.warn("WEBGL_color_buffer_float webgl extension not present."),this.onContextRestored=void 0,this.lifetimeCounter=0,this.canvas.addEventListener("webglcontextrestored",function(e){e.preventDefault(),r.recomputeProperties(),void 0!==r.onContextRestored&&r.onContextRestored()},!1),this.canvas.addEventListener("webglcontextlost",function(e){e.preventDefault(),r.lifetimeCounter++},!1),this.recomputeProperties()},{invalidateExistingResources:function(){this.lifetimeCounter++},recomputeProperties:function(){this.lifetimeCounter++,this.maxTextureUnits=this.gl.getParameter(WebGLRenderingContext.MAX_TEXTURE_IMAGE_UNITS),this.maxTextureSize=this.gl.getParameter(WebGLRenderingContext.MAX_TEXTURE_SIZE),this.maximumShaderFloatPrecision=this._getMaximumShaderFloatPrecision()},_getMaximumShaderFloatPrecision:function(){var e=this.gl,t=WebGLRenderingContext,r=function(r,n){var i=e.getShaderPrecisionFormat(r,n);return e.getError()===t.NO_ERROR&&void 0!==i&&null!==i&&i.precision>0};return r(t.VERTEX_SHADER,t.HIGH_FLOAT)&&r(t.FRAGMENT_SHADER,t.HIGH_FLOAT)?"highp":(console.warn("WebGL high precision not available."),r(t.VERTEX_SHADER,t.MEDIUM_FLOAT)&&r(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT)?"mediump":(console.warn("WebGL medium precision not available."),"lowp"))}},{})}(),a=void 0;return{get initializedWglContext(){return e}}}),$traceurRuntime.registerModule("src/webgl/WglMortalValueSlot.js",[],function(){"use strict";var e=function(){return $traceurRuntime.createClass(function(e,t){this.initializer=e,this.deinitializer=t,this.lifetimeId=void 0,this.mortalValue=void 0},{initializedValue:function(e){return this.lifetimeId!==e&&(this.ensureDeinitialized(),this.mortalValue=this.initializer(),this.lifetimeId=e),this.mortalValue},ensureInitialized:function(e){this.initializedValue(e)},ensureDeinitialized:function(){if(void 0!==this.lifetimeId){var e=this.mortalValue;this.lifetimeId=void 0,this.mortalValue=void 0,this.deinitializer(e)}}},{})}();return{get WglMortalValueSlot(){return e}}}),$traceurRuntime.registerModule("src/webgl/WglShader.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/webgl/WglShader.js")).Config,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/WglShader.js")).DetailedError,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglArg.js","src/webgl/WglShader.js")).WglArg,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglContext.js","src/webgl/WglShader.js")).initializedWglContext,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglMortalValueSlot.js","src/webgl/WglShader.js")).WglMortalValueSlot,a=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglUtil.js","src/webgl/WglShader.js")),o=a.checkGetErrorResult,u=a.checkFrameBufferStatusResult,s=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Seq.js","src/webgl/WglShader.js")).Seq,c=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/webgl/WglShader.js")).WglConfiguredShader,l=new i(function(){var e=WebGLRenderingContext,t=n().gl,r=t.createBuffer(),i=new Float32Array([-1,1,1,1,-1,-1,1,-1]);t.bindBuffer(e.ARRAY_BUFFER,r),t.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW);var a=t.createBuffer(),o=new Uint16Array([0,2,1,2,3,1]);return t.bindBuffer(e.ELEMENT_ARRAY_BUFFER,a),t.bufferData(e.ELEMENT_ARRAY_BUFFER,o,e.STATIC_DRAW),{positionBuffer:r,indexBuffer:a}},function(){}),d=function(){return $traceurRuntime.createClass(function(e){if("string"==typeof e){var t=e;e=function(){return t}}this.fragmentShaderSourceGenerator=e,this._compiledShaderSlot=void 0},{withArgs:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=this;if(void 0===this._compiledShaderSlot){var a=e.map(function(e){return e.name});this._compiledShaderSlot=new i(function(){return new m(r.fragmentShaderSourceGenerator(),a)},function(e){return e.free()})}return new c(function(t){if(0!==t.width&&0!==t.height){var i=WebGLRenderingContext,a=n(),s=a.gl;l.ensureInitialized(a.lifetimeCounter),s.bindFramebuffer(i.FRAMEBUFFER,t.initializedFramebuffer()),o(s,"framebufferTexture2D",!0),u(s,!0),r._compiledShaderSlot.initializedValue(a.lifetimeCounter).useWithArgs(e),s.viewport(0,0,t.width,t.height),s.drawElements(i.TRIANGLES,6,i.UNSIGNED_SHORT,0),o(s,"drawElements",!0),t.markRendered()}})},ensureDeinitialized:function(){void 0!==this._compiledShaderSlot&&this._compiledShaderSlot.ensureDeinitialized()},toString:function(){return"WglShader(fragmentShaderSource: "+this.fragmentShaderSourceGenerator()+")"}},{})}(),m=function(){function i(t,r){var a=n(),o=a.maximumShaderFloatPrecision,u="\n precision "+o+" float;\n precision "+o+" int;\n attribute vec2 position;\n void main() {\n gl_Position = vec4(position, 0, 1);\n }",c="\n precision "+o+" float;\n precision "+o+" int;\n "+t,l=WebGLRenderingContext,d=a.gl,m=i.compileShader(d,l.VERTEX_SHADER,u),f=i.compileShader(d,l.FRAGMENT_SHADER,c),h=d.createProgram();d.attachShader(h,m),d.attachShader(h,f),d.linkProgram(h);var g=d.getProgramInfoLog(h).trim();if(""!==g&&"\0"!==g&&e.SUPPRESSED_GLSL_WARNING_PATTERNS.every(function(e){return!e.test(g)})&&console.warn("Shader compile caused warnings","gl.getProgramInfoLog()",g),!1===d.getProgramParameter(h,l.LINK_STATUS))throw new Error("Failed to link shader program.\n\ngl.VALIDATE_STATUS: "+d.getProgramParameter(h,l.VALIDATE_STATUS)+"\ngl.getError(): "+d.getError());d.deleteShader(m),d.deleteShader(f),this.uniformLocations=new s(r).toMap(function(e){return e},function(e){return d.getUniformLocation(h,e)}),this.positionAttributeLocation=d.getAttribLocation(h,"position"),this.program=h}return $traceurRuntime.createClass(i,{useWithArgs:function(e){var i=n(),a=i.gl;a.useProgram(this.program);var o={coopTextureUnit:0},u=!0,s=!1,c=void 0;try{for(var l=void 0,d=e[Symbol.iterator]();!(u=(l=d.next()).done);u=!0){var m=l.value,f=this.uniformLocations.get(m.name);if(void 0===f)throw new t("Unexpected uniform argument",{arg:m,uniformArgs:e});r.INPUT_ACTION_MAP.get(m.type)(i,f,m.value,o)}}catch(e){s=!0,c=e}finally{try{u||null==d.return||d.return()}finally{if(s)throw c}}a.enableVertexAttribArray(this.positionAttributeLocation),a.vertexAttribPointer(this.positionAttributeLocation,2,WebGLRenderingContext.FLOAT,!1,0,0)},free:function(){n().gl.deleteProgram(this.program)}},{compileShader:function(e,t,r){var n=e.createShader(t);e.shaderSource(n,r),e.compileShader(n);var i=e.getShaderInfoLog(n);if(""!==i&&(console.warn("WebGLShader: gl.getShaderInfoLog() wasn't empty: "+e.getShaderInfoLog(n)),console.warn("Source code was: "+r)),!1===e.getShaderParameter(n,WebGLRenderingContext.COMPILE_STATUS))throw new Error("WebGLShader: Shader compile failed.\n Info: "+i+"\n Source: "+r);return n}})}();return{get WglShader(){return d}}}),$traceurRuntime.registerModule("src/webgl/WglTexture.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/WglTexture.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/Util.js","src/webgl/WglTexture.js")).Util,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglMortalValueSlot.js","src/webgl/WglTexture.js")).WglMortalValueSlot,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglContext.js","src/webgl/WglTexture.js")).initializedWglContext,i=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglUtil.js","src/webgl/WglTexture.js")),a=i.checkGetErrorResult,o=i.checkFrameBufferStatusResult,u=function(){function i(n,a){var o=void 0!==arguments[2]?arguments[2]:WebGLRenderingContext.FLOAT,u=this;if(0===n&&0===a)return this.width=0,this.height=0,this.pixelType=o,this._hasBeenRenderedTo=!0,void(this._textureAndFrameBufferSlot=new r(function(){throw new e("Touched a zero-size texture.",u)},function(){throw new e("Touched a zero-size texture.",u)}));if(!t.isPowerOf2(n)||!t.isPowerOf2(a))throw new e("Sizes must be a power of 2.",{width:n,height:a,pixelType:o});this.width=n,this.height=a,this.pixelType=o,this._hasBeenRenderedTo=!1,this._textureAndFrameBufferSlot=new r(function(){return u._textureAndFramebufferInitializer()},function(e){return i._deinitialize(e)})}return $traceurRuntime.createClass(i,{sizePower:function(){return 0===this.width?-1/0:Math.round(Math.log2(this.width*this.height))},toString:function(){return"Texture("+[this.width+"x"+this.height,this.pixelType===WebGLRenderingContext.FLOAT?"FLOAT":this.pixelType===WebGLRenderingContext.UNSIGNED_BYTE?"UNSIGNED_BYTE":this.pixelType,this._hasBeenRenderedTo?"rendered":"not rendered"].join(", ")+")"},markRendered:function(){this._hasBeenRenderedTo=!0},invalidateButMoveToNewInstance:function(t){var n=new i(this.width,this.height,this.pixelType);n._textureAndFrameBufferSlot=this._textureAndFrameBufferSlot;var a=function(){throw new e("WglTexture's value accessed after invalidation.",t)};return this._textureAndFrameBufferSlot=new r(a,a),n},initializedTexture:function(){if(!this._hasBeenRenderedTo)throw new Error("Called initializedTexture on a texture that hasn't been rendered to.");return this._textureAndFrameBufferSlot.initializedValue(n().lifetimeCounter).texture},initializedFramebuffer:function(){return this._textureAndFrameBufferSlot.initializedValue(n().lifetimeCounter).framebuffer},ensureDeinitialized:function(){this._textureAndFrameBufferSlot.ensureDeinitialized()},_textureAndFramebufferInitializer:function(){var e=WebGLRenderingContext,t=n().gl,r={texture:t.createTexture(),framebuffer:t.createFramebuffer()};t.bindTexture(e.TEXTURE_2D,r.texture),t.bindFramebuffer(e.FRAMEBUFFER,r.framebuffer);try{t.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),t.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),t.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),t.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),t.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.width,this.height,0,e.RGBA,this.pixelType,null),a(t,"texImage2D"),t.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r.texture,0),a(t,"framebufferTexture2D"),o(t)}finally{t.bindTexture(e.TEXTURE_2D,null),t.bindFramebuffer(e.FRAMEBUFFER,null)}return r},readPixels:function(){var e=void 0===arguments[0]||arguments[0],t=WebGLRenderingContext;if(!this._hasBeenRenderedTo)throw new Error("Called readPixels on a texture that hasn't been rendered to.");var r;switch(this.pixelType){case t.UNSIGNED_BYTE:r=new Uint8Array(this.width*this.height*4);break;case t.FLOAT:r=new Float32Array(this.width*this.height*4);break;default:throw new Error("Unrecognized pixel type.")}if(0===this.width||0===this.height)return r;var i=n().gl;return i.bindFramebuffer(t.FRAMEBUFFER,this.initializedFramebuffer()),a(i,"framebufferTexture2D",e),o(i,e),i.readPixels(0,0,this.width,this.height,t.RGBA,this.pixelType,r),a(i,"readPixels(..., RGBA, "+this.pixelType+", ...)",e),r}},{preferredWidthHeightForSizePower:function(e){var t=1<<Math.ceil(e/2),r=1<<Math.floor(e/2);return 2===t&&2===r&&(t=4,r=1),{w:t,h:r}},_deinitialize:function(e){var t=e,r=t.texture,i=t.framebuffer,a=n().gl;a.deleteTexture(r),a.deleteFramebuffer(i)}})}();return{get WglTexture(){return u}}}),$traceurRuntime.registerModule("src/webgl/WglTexturePool.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/base/DetailedError.js","src/webgl/WglTexturePool.js")).DetailedError,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexture.js","src/webgl/WglTexturePool.js")).WglTexture,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/webgl/WglTexturePool.js")).provideWglTexturePoolToWglConfiguredShader,n=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/ShaderCoders.js","src/webgl/WglTexturePool.js")).currentShaderCoder,i=[],a=[],o=0,u=function(){function r(){}return $traceurRuntime.createClass(r,{},{_bucketFor:function(t,r){if(!Number.isInteger(t)||t<0||t>50)throw new e("Bad sizePower",{sizePower:t,pixelType:r});for(var n=r===WebGLRenderingContext.FLOAT?i:a;n.length<=t;)n.push([]);return n[t]},take:function(e,n){if(e===-1/0)return new t(0,0,n);var i=r._bucketFor(e,n);if(++o>1e3&&console.warn("High borrowed texture count: "+o+". (Maybe a leak?)"),i.length>0)return i.pop();var a=t.preferredWidthHeightForSizePower(e),u=a.w,s=a.h;return new t(u,s,n)},deposit:function(n){var i=void 0!==arguments[1]?arguments[1]:"[no dealloc details]";if(!(n instanceof t))throw new e("Not a texture",{texture:n,detailsShownWhenUsedAfterDone:i});if(0!==n.width){var a=r._bucketFor(n.sizePower(),n.pixelType);o--,a.push(n.invalidateButMoveToNewInstance(i))}},takeSame:function(e){return r.take(e.sizePower(),e.pixelType)},getUnReturnedTextureCount:function(){return o},takeRawFloatTex:function(e){return r.take(e,WebGLRenderingContext.FLOAT)},takeRawByteTex:function(e){return r.take(e,WebGLRenderingContext.UNSIGNED_BYTE)},takeBoolTex:function(e){return r.take(e,WebGLRenderingContext.UNSIGNED_BYTE)},takeVecFloatTex:function(e){return r.take(e+n().float.powerSizeOverhead,n().float.pixelType)},takeVec2Tex:function(e){return r.take(e+n().vec2.powerSizeOverhead,n().vec2.pixelType)},takeVec4Tex:function(e){return r.take(e+n().vec4.powerSizeOverhead,n().vec4.pixelType)}})}();return t.prototype.deallocByDepositingInPool=function(){var e=arguments[0];u.deposit(this,e)},r(u),{get WglTexturePool(){return u}}}),$traceurRuntime.registerModule("src/webgl/WglTextureTrader.js",[],function(){"use strict";var e=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglConfiguredShader.js","src/webgl/WglTextureTrader.js")).WglConfiguredShader,t=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexture.js","src/webgl/WglTextureTrader.js")).WglTexture,r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/webgl/WglTexturePool.js","src/webgl/WglTextureTrader.js")).WglTexturePool,n=function(){return $traceurRuntime.createClass(function(e){this.currentTexture=e,this._dontDeallocFlag=!1},{dontDeallocCurrentTexture:function(){return this._dontDeallocFlag=!0,this.currentTexture},shadeAndTrade:function(t){var n=arguments[1],i=this.currentTexture,a=!this._dontDeallocFlag,o=n||r.takeSame(i);(t instanceof e?t:t(i)).renderTo(o),this.currentTexture=o,this._dontDeallocFlag=!1,a&&i.deallocByDepositingInPool("WglTexturePool shadeAndTrade")},shadeHalveAndTrade:function(e){this.shadeAndTrade(e,r.take(Math.max(0,this.currentTexture.sizePower()-1),this.currentTexture.pixelType))},shadeQuarterAndTrade:function(e){this.shadeAndTrade(e,r.take(Math.max(0,this.currentTexture.sizePower()-2),this.currentTexture.pixelType))}},{})}();return t.prototype.tradeThrough=function(e){var t=void 0!==arguments[1]&&arguments[1],r=new n(this);return t&&r.dontDeallocCurrentTexture(),e(r),r.currentTexture},{get WglTextureTrader(){return n}}}),$traceurRuntime.registerModule("src/webgl/WglUtil.js",[],function(){"use strict";function e(e,t){var n;if(!(void 0!==arguments[2]&&arguments[2])||r.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS){var i=e.getError(),a=WebGLRenderingContext;if(i!==a.NO_ERROR){var o=(n={},Object.defineProperty(n,1280,{value:"INVALID_ENUM [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,1281,{value:"INVALID_VALUE [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,1282,{value:"INVALID_OPERATION [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,1285,{value:"OUT_OF_MEMORY [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,1286,{value:"INVALID_FRAMEBUFFER_OPERATION [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,37442,{value:"CONTEXT_LOST_WEBGL [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.INVALID_ENUM,{value:"INVALID_ENUM",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.INVALID_VALUE,{value:"INVALID_VALUE",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.INVALID_OPERATION,{value:"INVALID_OPERATION",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.OUT_OF_MEMORY,{value:"OUT_OF_MEMORY",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.INVALID_FRAMEBUFFER_OPERATION,{value:"INVALID_FRAMEBUFFER_OPERATION",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(n,a.CONTEXT_LOST_WEBGL,{value:"CONTEXT_LOST_WEBGL",configurable:!0,enumerable:!0,writable:!0}),n),u=void 0!==o[i]?o[i]:"?";throw new Error("gl.getError() returned 0x"+i.toString(16)+" ("+u+") after "+t+".")}}}function t(e){var t;if(!(void 0!==arguments[1]&&arguments[1])||r.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS){var n=WebGLRenderingContext,i=e.checkFramebufferStatus(n.FRAMEBUFFER);if(i!==n.FRAMEBUFFER_COMPLETE){var a=(t={},Object.defineProperty(t,0,{value:"Argument wasn't a frame buffer",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,1280,{value:"INVALID_ENUM [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,36054,{value:"FRAMEBUFFER_INCOMPLETE_ATTACHMENT [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,36055,{value:"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,36057,{value:"FRAMEBUFFER_INCOMPLETE_DIMENSIONS [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,36061,{value:"FRAMEBUFFER_UNSUPPORTED [+constant not found]",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,n.INVALID_ENUM,{value:"INVALID_ENUM",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT,{value:"FRAMEBUFFER_INCOMPLETE_ATTACHMENT",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,{value:"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS,{value:"FRAMEBUFFER_INCOMPLETE_DIMENSIONS",configurable:!0,enumerable:!0,writable:!0}),Object.defineProperty(t,n.FRAMEBUFFER_UNSUPPORTED,{value:"FRAMEBUFFER_UNSUPPORTED",configurable:!0,enumerable:!0,writable:!0}),t),o=void 0!==a[i]?a[i]:"?";throw new Error("gl.checkFramebufferStatus() returned 0x"+i.toString(16)+" ("+o+").")}}}var r=$traceurRuntime.getModule($traceurRuntime.normalizeModuleName("src/Config.js","src/webgl/WglUtil.js")).Config;return{get checkGetErrorResult(){return e},get checkFrameBufferStatusResult(){return t}}}),$traceurRuntime.getModule("src/main.js");
</script>
</body>
</html>