Skip to content

engine: unordered or NaN graphical-function x values are not rejected #715

Closed

Description

@bpowers

A graphical function whose x values are out of order, NaN, or infinite reached the VM without any error.
The lookup's binary search assumes ascending x, so such a table gave an arbitrary interpolated value.

Example

XMILE <xpts>0,10,5,20</xpts> compiled and simulated with no diagnostic.
The only out-of-order table in the test corpus is Vensim's lookup2dim[B,E]((2,-3),(1,-7),(0,-1)) in test/test-models/tests/subscripted_lookups/test_subscripted_lookups.mdl.

Status

On main, parse_table (src/simlin-engine/src/variable.rs) rejects a NaN or infinite x and any x that is lower than the one before it, with a BadTable error naming the values.
The MDL importer sorts out-of-order points into x order, matching Vensim's own output for the model above (simulates_subscripted_lookups_mdl and a_vensim_lookup_listed_out_of_x_order_is_imported_in_x_order in src/simlin-engine/tests/integration/simulate.rs).
XMILE 1.0 section 4.1.3 requires ascending x, so XMILE input is rejected rather than sorted.

Activity

  1. added
    engine
    bug
    on Jun 8, 2026
  2. bpowers commented on Aug 10, 2026

    @bpowers
    OwnerAuthor

    A corpus census of every graphical function the engine can read (558 tables across 64 files, via open_vensim/open_xmile so the shapes are the ones the compiler sees) turns up exactly one unsorted table, and it is a live instance of this issue rather than a near-miss:

    test/test-models/tests/subscripted_lookups/test_subscripted_lookups.mdl — a 3-point table whose x-coordinates are [2.0, 1.0, 0.0], i.e. strictly descending. It reaches the VM with no diagnostic and produces an arbitrary interpolation today.

    Two facts that matter for prioritizing:

    • Nothing covers it. That model is not in the gated TEST_MODELS corpus, which is why this has never surfaced as a failure. So the current behaviour is not merely undefined, it is unobserved.
    • 557 of 558 corpus tables are strictly ascending (0 have duplicate x). So validation would reject or repair exactly one known model, not a long tail — the back-compat surface for stored projects is the open question, not the corpus.

    For the census record, since it bears on any fix that wants a fast path: 483 tables (86.6%) are exactly uniform in x, 26 (4.7%) are uniform only to within a 1e-9 relative tolerance — the 0.1, 0.2, 0.3 binary-floating-point case, which includes 8 of WORLD3's 55 tables — and 48 (8.6%) are genuinely non-uniform.

  3. changed the title [-]engine: graphical-function tables with unsorted/NaN x-coordinates are accepted silently and produce undefined lookup results[/-] [+]engine: unordered or NaN graphical-function x values are not rejected[/+] on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing: already fixed on main.

    parse_table (src/simlin-engine/src/variable.rs:356-382, 610cb2c / #1071) returns BadTable for a NaN x, an infinite x, or any x below its predecessor, citing XMILE 1.0 section 4.1.3; tests x_values_out_of_ascending_order_are_a_bad_table, a_model_with_decreasing_x_reports_a_bad_table_on_its_variable and a_model_with_a_nan_x_reports_a_bad_table_on_its_variable (variable.rs:995, 1146, 1166) pin it down to the model diagnostic. The MDL importer sorts instead (points_in_x_order, mdl/convert/variables.rs:1564), checked against Vensim's own output by simulates_subscripted_lookups_mdl and a_vensim_lookup_listed_out_of_x_order_is_imported_in_x_order (tests/integration/simulate.rs:2933, 2946).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions