Skip to content

feat: sum_forward, the window sum_back already was pointed the other way - #56

Closed
FBumann wants to merge 1 commit into
mainfrom
feat/sum-forward
Closed

FBumann wants to merge 1 commit into
mainfrom
feat/sum-forward

Conversation

@FBumann

@FBumann FBumann commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

sum_forward(<expr>, over=<dim>, within=<n|parameter>[, edge='wrap'][, by=<lookup>]) — sums the next n positions along an axis, where sum_back sums the last n.

  • operators.py, dimensions.py, degree.py — the operator, its dim rule, its place among the reductions.
  • typesetting/walk.py — one branch renders both windows; _WINDOWS decides only which side of the lag operator the written index falls on.
  • Four examples (sum_forward, _by_parameter, _wrap, _partitioned), three golden constraints, generator rows; docs regenerated.

Also carries the sum_forward half of #59: by= partitions a leading window exactly as it does a trailing one.

Why

sum_back and sum_forward are one operator with a direction. Spelling that direction in the name rather than in the sign of a width keeps the width a count — which is what every rule about it already assumes — and lets the typesetter render both from one place:

seasonal_window   ∑_{t' ∈ 𝒯 : 0 ≤ t  -^season_of(t) t' < 3} on_{t',g} ≤ units_g
seasonal_outlook  ∑_{t' ∈ 𝒯 : 0 ≤ t' -^season_of(t) t  < 3} on_{t',g} ≤ units_g

Same operator, operands swapped.

The sum_back half of #59 was split out into #65, since it fixed a rule main already documented in the BUILTINS comment and already checked in _dims_call — only the builtin declaration was missing, so the rule was unreachable. #59 is now closed as superseded.

Landing order

Merge #65 first. This branch is built on it — the partitioned-window typesetting (_group) comes from there — but GitHub refuses to retarget this PR's base ("the pull request is part of a stack", left over from the closed #59), so it still points at main and its diff shows #65's commit as well. Once #65 lands, rebasing this branch onto main drops that commit and the diff is sum_forward alone.

#61 → #63 also branch off #65, in parallel with this. Both this PR and #61 touch dimensions.py around the named-amount rules; whichever lands second needs the sum_forward keys added back to _AMOUNTS / _VARIES (and _NEGATED, from #63). That is a few lines rather than a conflict in the operator itself — but it argues for landing #61/#63 first, so those dicts get written once with both windows in them.

Rebased onto main: the three wording tables are one, the window branch
reads the reduction the way main's walk does, and the tests sit in the
parametrized tables.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@FBumann

FBumann commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (alpha.24). The three wording tables the PR carried are main's one _AMOUNT_WORDING with a sum_forward row; the window branch reads the reduction the way main's walk does. Gate: pytest, strict docs, compile-tex.

@FBumann FBumann added the area: operators What an operator may reduce, walk, read or refuse label Sep 15, 2026 — with Claude

FBumann commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Note

The following content was generated by AI.

Closed at the author's request, in a sweep of the open PRs. Closed rather than rebased, because the operator surface this branch adds is written in a spelling main no longer uses.

The facts behind that:

Rebasing it would mean rewriting the operator declaration, the dim rule, the typesetting branch, four examples and three golden constraints against the new names. That is the work of writing it again, without the benefit of starting from what the language looks like today.

The feature is still wanted. sum_back and sum_forward are one operator with a direction, and the argument in this PR's description holds. It needs a fresh branch against current main, with along= as the axis keyword.


Generated by Claude Code

@FBumann FBumann closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: operators What an operator may reduce, walk, read or refuse

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant