Skip to content

should_apply_default_to_missing heuristic fails for non-constant EXCEPT equations #356

Closed

Description

@bpowers

Problem

The should_apply_default_to_missing heuristic in variable.rs uses text matching to distinguish EXCEPT-originated sparse arrays from override-style sparse arrays. The current all() heuristic checks whether ALL explicitly-specified elements match the default equation text. This works for constant equations but fails for non-constant EXCEPT equations where per-element substitution changes the text.

For example, in an equation like y[DimA] :EXCEPT: y[a2] = special_value, the EXCEPT expansion produces element equations where y[a2] differs from y[DimA] due to subscript substitution, causing the heuristic to incorrectly conclude that the array is override-style rather than EXCEPT-originated.

Why it matters

  • Correctness: When the heuristic misclassifies an EXCEPT-originated sparse array as override-style, array defaults are not applied to missing elements, producing incorrect simulation results.
  • Maintainability: Text-based inference of semantic intent is fragile and will break again as equation transformations become more sophisticated.

Components affected

  • src/simlin-engine/src/variable.rs (should_apply_default_to_missing)
  • src/simlin-engine/src/datamodel.rs (Equation::Arrayed)
  • src/simlin-engine/src/mdl/convert/variables.rs (MDL converter EXCEPT expansion)

Proposed fix

Add an explicit boolean flag (e.g., has_default: bool or from_except: bool) to Equation::Arrayed in the datamodel. The MDL converter should set this flag during EXCEPT expansion, making the semantics explicit rather than inferred from text comparison. This eliminates the fragile heuristic entirely.

Note: changes to Equation::Arrayed in the datamodel will require corresponding updates to the protobuf definition and serialization, since the datamodel is serialized to Firestore.

Context

Identified during review of the mdl-full-compat branch (PR #343 review feedback).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions