|
1 | | -"""Shared scaffolding for the three calculator examples. |
| 1 | +r"""Shared scaffolding for the three calculator examples. |
2 | 2 |
|
3 | 3 | ``calculator_simple`` and ``calculator_advanced`` are two *independent* |
4 | 4 | implementations of the same calculator: they differ only in their arithmetic — |
@@ -185,7 +185,7 @@ def compare_digit_seqs( |
185 | 185 |
|
186 | 186 | flags = [ |
187 | 187 | onehot_lookup(concat([a, b]), pair_table, default_flag) |
188 | | - for a, b in zip(seq1, seq2) # MSB-first |
| 188 | + for a, b in zip(seq1, seq2, strict=False) # MSB-first |
189 | 189 | ] |
190 | 190 | # Sharpen each flag to an exact three-level value: gt = 1 iff flag > 0.5, |
191 | 191 | # lt = 1 iff flag < -0.5 (both bit-exact in saturation; the flag sits |
@@ -215,7 +215,7 @@ def parse_expression( |
215 | 215 | embedding: Embedding, |
216 | 216 | max_digits: int, |
217 | 217 | ) -> tuple[list[Node], list[Node], Node, Node, Node, Node]: |
218 | | - """Parse ``"A op B\\n"`` from the token stream, at constant depth. |
| 218 | + r"""Parse ``"A op B\\n"`` from the token stream, at constant depth. |
219 | 219 |
|
220 | 220 | Returns ``(first, second, is_plus, is_minus, is_times, saw_newline)``: |
221 | 221 | the two operand digit windows (MSB-first, zero-padded to ``max_digits``), |
@@ -383,13 +383,13 @@ def build_calculator( |
383 | 383 |
|
384 | 384 | # --- Addition: pad each operand by one digit so the top carry has a home. --- |
385 | 385 | add_seq = _pad_result( |
386 | | - embedding, add_digit_seqs(embedding, [zero] + first, [zero] + second), seq_len |
| 386 | + embedding, add_digit_seqs(embedding, [zero, *first], [zero, *second]), seq_len |
387 | 387 | ) |
388 | 388 |
|
389 | 389 | # --- Subtraction: |A - B| by a borrow fold, sign from the comparison. --- |
390 | 390 | a_ge_b = compare_digit_seqs(embedding, first, second) |
391 | | - bigger = [select(a_ge_b, a, b) for a, b in zip(first, second)] |
392 | | - smaller = [select(a_ge_b, b, a) for a, b in zip(first, second)] |
| 391 | + bigger = [select(a_ge_b, a, b) for a, b in zip(first, second, strict=False)] |
| 392 | + smaller = [select(a_ge_b, b, a) for a, b in zip(first, second, strict=False)] |
393 | 393 | sub_seq = _pad_result( |
394 | 394 | embedding, subtract_digit_seqs(embedding, bigger, smaller), seq_len |
395 | 395 | ) |
|
0 commit comments