Skip to content

relalg (D-RA-1): relational IR rewritten before it runs, lowered through R2IL — a D-CMR prototype - #1546

Merged
AdaWorldAPI merged 4 commits into
mainfrom
ccr-9f3b8075-74u47l-relalg
Oct 14, 2026
Merged

AdaWorldAPI merged 4 commits into
mainfrom
ccr-9f3b8075-74u47l-relalg

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

What

New crate crates/lance-graph-relalg. It has its own workspace root and is excluded from the default build, like lance-graph-nal, because it path-deps lance-graph-r2il and through it OGAR. It is a prototype for D-CMR (.claude/plans/d-cmr-concept-chain-normalization-v1.md): rearrange a query's description with proven identities before anything runs, and lower only what is left.

  • Rel describes a set of rows of one table: All, Empty, a resident plane, one comparison on an I32 or U32 lane, and And / Or / Not. A Query is a Rel plus a measure (Count, Sum, Min, Max, Keep).
  • No strings in the IR. Lanes are indexes, constants are numbers, and Atom, Cmp and Measure must be Copy (checked at compile time). Names are labels resolved through the label codebook and never become part of a description.
  • normalize rewrites to a fixpoint:
    • negation pushed to the leaves;
    • flattening, unit and zero;
    • duplicates removed;
    • p ∧ ¬p = ∅, p ∨ ¬p = U;
    • per I32 lane, a conjunction becomes one value interval plus the excluded values inside it;
    • overlapping or adjacent intervals in a disjunction are merged;
    • U32 equalities either agree or contradict;
    • absorption.
  • symbolic answers ∅, and U for a count, without running a program.
  • run lowers to R2IL calls over FoldDialect (LOAD, IntSLess, IntEqual, IntAnd/Or/Not, RANGE, then PopCount/SUM/MIN/MAX/KEEP). mask-risc executes them; the crate has no row loop.

Measured

Run with cargo test --manifest-path crates/lance-graph-relalg/Cargo.toml: 10 tests pass, clippy -D warnings and fmt are clean.

check result
400 generated descriptions × 5 measures rewritten == as written == row oracle; rewriting is idempotent; 273/400 descriptions change
four comparisons on one lane 2 mask-risc ops rewritten, 8 as written
x=3 ∨ x=4 ∨ x=5 2 ops rewritten, 5 as written
contradictions, tautologies answered with 0 programs
ten comparisons on one lane refused as written (ScratchBufferTooSmall); runs after the rewrite

Finding: the rewrite decides whether a query fits into one fold at all, not just how fast it runs. A fold has 8 scratch slots, and every negation in the as-written form takes one. 70 of 2,000 small runs therefore do not lower as written, and all of them run after the rewrite.

Disable runs: each guard was removed in turn, and each removal turned at least one test red:

  • fusing across lanes;
  • no symbolic answer;
  • no absorption;
  • union ignoring adjacency;
  • no end tightening;
  • ≤ negated to ≥;
  • no complement check;
  • < off by one;
  • a String in a measure (compile error).

Relation to D-CMR

D-CMR puts the set algebra in lance-graph-contract. It is explicitly not meant to be a third query syntax beside Quack's Filter and NAL's R2IL programs. This crate is evidence for that plan, not a competitor:

  • its rules are D-CMR-6 constraint propagation over residual comparisons;
  • its lowering does D-CMR-2's job via NAL's R2IL route;
  • D-RA-2 moves the rules into the contract set IR, after which relalg keeps only the lowering or is deleted.

Not built: joins (a hop is a preimage over coordinates, D-CMR-5, never a foreign key), recursion (D-RA-4), row intervals, and Datalog rules (D-RA-3). Datalog rules will be algebra values, with names only as codebook labels.

Board

  • .claude/plans/relalg-v1.md
  • STATUS_BOARD section D-RA (D-RA-1 In PR, D-RA-2..4 Queued)
  • INTEGRATION_PLANS entry
  • Cargo.toml exclude entry

🤖 Generated with Claude Code

https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh


Generated by Claude Code

…R2IL (D-RA-1)

A query is described as a selection over one table's row space (All,
Empty, Plane, comparison atoms, And/Or/Not) plus a measure. normalize()
rewrites the description before anything runs: negation to the leaves,
flattening and unit/zero absorption, complement, interval fusion per
I32 lane in conjunctions, interval union in disjunctions, U32 equality
agreement, absorption. A description that normalizes to Empty (or All,
for a count) is answered without a program. Everything else lowers into
R2IL calls over FoldDialect, which builds and runs one mask-risc program
per fold.

tests/rewrites.rs checks rewritten == as written == a row oracle over
400 generated descriptions and five measures, plus the cost effects
(fewer passes, no program for contradictions and tautologies, a
ten-way conjunction that only fits the scratch arena after fusion).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
relalg-v1 maps the crate onto D-CMR: the rules are D-CMR-6 constraint
propagation over residual comparisons, the R2IL lowering is D-CMR-2's
job by NAL's route, and D-RA-2 moves the rules into the contract set
IR. Measured in the plan: 8 -> 2 mask-risc ops for four comparisons on
one lane, contradictions and tautologies with no program, and 70 of
2,000 small descriptions that fit one fold only after the rewrite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
Atom, Cmp and Measure must be Copy (compile-time guard), so no String
can enter a description. D-RA-3 is re-scoped: a rule is a Rel built
from coordinates; names are labels resolved once through the label
codebook, never stored in a rule or used as an address, and text is a
label view, never a query path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c55a4a7d-526c-44d1-9b34-ea476986e322
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 13, 2026 22:49
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T22:54:50.052586Z c7e4732 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7e4732adc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/lance-graph-relalg/src/normalize.rs
x = t ∨ x ≠ t stayed unrewritten because equalities went to the
interval map and inequalities to the rest (codex review on #1546).
A union now treats x ≠ a like the U32 case: a second inequality or an
interval holding a covers the lane; otherwise the intervals are inside
x ≠ a and absorbed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
@AdaWorldAPI
AdaWorldAPI merged commit c21bd16 into main Oct 14, 2026
13 checks passed
AdaWorldAPI added a commit that referenced this pull request Oct 14, 2026
…board

board: record #1546 (D-RA-1 relalg) and #1545 as merged
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