Skip to content

Widen rule coverage: printf, filter, 26 more rules, adversarial pass - #3

Merged
evangress merged 4 commits into
mainfrom
coverage
Nov 14, 2026
Merged

evangress merged 4 commits into
mainfrom
coverage

Conversation

@evangress

Copy link
Copy Markdown
Contributor

Makes dualect useful on more real scripts.

Changes

  • Corpus holes closed: printf/fprintf/sprintf/disp format translation and filter() → scipy.signal.lfilter. beam_deflection and signal_filter now translate fully and verify in both directions. Verify can now compare printed output (% dualect: stdout).
  • Coverage: 35 → 61 rules, 88 case pairs. .m → Python: 58 mechanical, 3 guided. Python → .m: 54 mechanical, 1 guided. Each rule supplies its own inference facts through hooks, so a new built-in stays one folder.
  • Promoted: multiple-returns, nargin, grow-on-assign, command-syntax. Still guided: display, nargout, tic/toc.
  • Adversarial pass: fixed integer overflow in x .^ 2 and A ^ 3, lost sign of -0, format long leaking between scripts, and several shape/view/dtype bugs; NaN-sensitive and other unprovable forms are declined by name. Regression tests added.
  • New corpus scripts: least_squares_fit (26/27), data_statistics (27/28), grid_heat (20/26); holes are reported, not hidden.
  • Tests prefer octave-cli so macOS does not show a Dock icon per run.
  • README, docs/index.html (TagCheck: 0 errors, 0 warnings), CLAUDE.md and llms.txt updated.

Test plan

  • uv run pytest (1409 passed locally, Octave 11)
  • ruff, mypy (package and rule translators), dualect rules check
  • CI on Ubuntu apt Octave 8.4

🤖 Generated with Claude Code

evangress and others added 4 commits November 14, 2026 10:27
…erify

io/printf (new, mechanical both ways) turns a literal printf format into an
f-string field by field and carries out the format's recycling statically;
one array argument recycles it per element or per column as a loop (or a
"".join for sprintf). %d of a value not known to be a whole number, %s of a
number, %x/%c/%u, * widths, file ids other than 1, empty arrays and disp of
a number are declined by name. io/display keeps the missing-semicolon case
and stays guided.

builtins/filter (new) is scipy.signal.lfilter, axis=0 for a matrix; SciPy
becomes a dependency. types/double (new) covers double()/logical() and
x.astype(float)/astype(bool), which the filter translation needs.

verify gains `% dualect: stdout`, comparing printed text exactly (the .m
side captured with evalc), and `% dualect: shape r` for random values;
translations that print add the directive themselves. -0 now keeps its
sign. corpus/beam_deflection.m and corpus/signal_filter.m translate fully
and verify in both directions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rules teach the analysis what their built-ins return (infer_call,
infer_outputs, pyinfer_call in translate.py), so a new built-in stays one
folder; multi-output built-ins lift through their own rule's lift_multi.

New rules, with cases in both languages: cumsum-cumprod, diff, any-all,
sort (stable index output), unique, flip, reshape (column-major), repmat,
concatenation-functions (cat/horzcat/vertcat), meshgrid, rand-randn
(compared by shape), norm, dot-cross-kron, linear-algebra (inv/det/trace/
rank), std-var (N-1), median, interp1 (NaN outside the range), polyfit-
polyval, trapz, type-tests, num2str, tic-toc (guided). Extended:
constants (true/false/Inf/NaN with sizes), elementwise-math (floor
division, real/imag/conj/log1p/expm1, mod/rem sign rules), size-numel-
length (ndims), sum-mean-max (min case, dtype=float lift). Forms that
cannot be proved are declined by name.

The Octave runner resets `format` between scripts (a `format long` leaked
into later display output), and Python-to-.m verification honours the
source's shape and stdout directives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rpus scripts

Promoted to mechanical after `dualect rules check` qualified them:
functions/multiple-returns (.m -> Python: tuple unpacking, `_`, output
slices; nargout-dependent bodies split into a guided functions/nargout),
functions/nargin (both ways: literal defaults in the header, None
defaults with `is None`/isempty when no caller may pass an empty value),
indexing/grow-on-assign (both ways: np.append, np.pad, np.zeros) and
syntax/command-syntax (display-only commands dropped with a comment,
`clear a b` is `del a, b`). io/display stays guided: the display format
of a missing semicolon depends on the value.

Integer powers: every exponent of 2 or more on an integer array, or on an
element read out of one, is a float, and an integer matrix power works in
floats (x .^ 2 wrapped around above 3037000499). A tall A \ b is a
least-squares solve; [m, i] = max(A) of a matrix gives per-column rows.

Adversarial probes of every new rule, both directions, against Octave:
tests/test_adversarial*.py. New corpus scripts: least_squares_fit.m,
data_statistics.m, grid_heat.m. README, docs/index.html, CLAUDE.md and
design.md carry the new numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plain `octave` resolves to octave-gui, which macOS treats as a foreground
app and shows in the Dock on every test run. An explicit OCTAVE_EXECUTABLE
still wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@evangress
evangress merged commit 7df9e24 into main Nov 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant