Skip to content

Add shared vector linear-recurrence optimization for multi-array NaturalArray loops#91

Merged
DanexCodr merged 13 commits into
mainfrom
copilot/enhance-natural-array-linear-recurrence
Apr 12, 2026
Merged

Add shared vector linear-recurrence optimization for multi-array NaturalArray loops#91
DanexCodr merged 13 commits into
mainfrom
copilot/enhance-natural-array-linear-recurrence

Conversation

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

This change extends recurrence optimization from single-array linear recurrences to N interconnected recurrences in one loop. It detects multi-assignment recurrence systems, builds a shared vector recurrence model, and evaluates per-array terms via shared rolling state for sequential access.

  • Vector recurrence model (new formula type)

    • Added VectorRecurrenceFormula to represent coupled recurrences across multiple arrays.
    • Supports:
      • dimension m (number of arrays/sequences)
      • order k (max lag)
      • constant vector
      • seed matrix
      • companion-matrix fallback for non-sequential/random access
    • Uses shared rolling state for sequential i -> i+1 evaluation.
  • NaturalArray integration

    • Added vector recurrence bindings in NaturalArray (formula + sequenceIndex).
    • Added vector recurrence evaluation path before scalar recurrence formulas.
    • Multiple arrays can now share one recurrence model while each array resolves its own sequence slot.
  • Loop optimizer: vector detection + extraction

    • Extended LoopOptimizationHandler to detect loop bodies with multiple assignments of form arr[i] = ....
    • Enforces linear structure over lagged indexed terms and extracts:
      • coefficient tensor (flattened to matrix form)
      • constant vector
      • recurrence start + seed window
    • Emits a new vector recurrence pattern for pattern application.
  • Pattern application

    • Extended PatternHandler with VECTOR_LINEAR_RECURRENCE.
    • Builds one shared VectorRecurrenceFormula per detected system and attaches it to all target arrays with stable sequence indices.
  • Coverage

    • Added VectorLinearRecurrenceOptimization.cod with coupled recurrence systems (including mixed lags and constant terms).
for i of [2 to N] {
    a[i] = a[i-1] + b[i-1]
    b[i] = a[i-1] - b[i-1]
}

This loop is now recognized as a single vector recurrence system and optimized as shared state instead of independent per-array fallback evaluation.

Copilot AI and others added 13 commits April 12, 2026 13:54
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/4e0ce258-ef41-4a6f-be38-ffa472d9e8b4

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/4e0ce258-ef41-4a6f-be38-ffa472d9e8b4

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/4e0ce258-ef41-4a6f-be38-ffa472d9e8b4

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/4e0ce258-ef41-4a6f-be38-ffa472d9e8b4

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/4e0ce258-ef41-4a6f-be38-ffa472d9e8b4

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/6399c570-b95d-4d37-a5ef-4f2b988df11d

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/6399c570-b95d-4d37-a5ef-4f2b988df11d

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/6399c570-b95d-4d37-a5ef-4f2b988df11d

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/6399c570-b95d-4d37-a5ef-4f2b988df11d

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/6399c570-b95d-4d37-a5ef-4f2b988df11d

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
@DanexCodr DanexCodr marked this pull request as ready for review April 12, 2026 21:41
@DanexCodr DanexCodr merged commit e90280b into main Apr 12, 2026
@DanexCodr DanexCodr deleted the copilot/enhance-natural-array-linear-recurrence branch April 12, 2026 21:42
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.

2 participants