Skip to content

runLengthEncode rewrite - #4532

Open
pzinn wants to merge 1 commit into
Macaulay2:developmentfrom
pzinn:rle
Open

runLengthEncode rewrite#4532
pzinn wants to merge 1 commit into
Macaulay2:developmentfrom
pzinn:rle

Conversation

@pzinn

@pzinn pzinn commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

this is a complete rewrite of the code in runLengthEncode.
I've also taken the opportunity to merge rle and runLengthEncode.
The behaviour should be mostly unchanged, except for a few extra Holders here and there for consistency and to fix obscure cases of the documented value behaviour.
And it fixes #4393. Repeated entries are encoded before consecutive entries. A range is encoded only when it has three entries or more. Tests added.
(There was already one related test in normal/formatting.m2 but I decided to leave it there and create a new test file.)

@pzinn

pzinn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

there are two failing examples:

  • one is easy, [x..y] should become [x,y]
  • the other is more problematic: currently [s_(1,1), s_(1,2), s_(2,1), s_(2,2)] becomes [s_(1,1)..s_(2,2)] which seems good to me. but after the PR we don't create ranges of length 2...

edited: all good now, first example corrected, and fixed code so second example unchanged

@pzinn
pzinn force-pushed the rle branch 5 times, most recently from ce5363a to 6262016 Compare August 5, 2026 05:00
@d-torrance

Copy link
Copy Markdown
Member

The following WeylAlgebras test is failing:

i14 : 
        -- Dbasics basics
        R = QQ[r,s];

i15 :   A = makeWeylAlgebra R;

i16 :   B = QQ[r,s,dr,ds,WeylAlgebra => {r=>dr,s=>ds}];

i17 :   assert (describe A===describe B);
stdio:22:8:(3):[1]: error: assertion failed

They look the same, but from what I can tell, the r, dr, s, and ds in the WeylAlgebra => {{r,dr}, {d,ds}} option below are now coming from different monoids:

i5 : describe A

o5 = QQ[r, s, dr, ds, Degrees => {4:1}, Heft => {1}, WeylAlgebra => {{r, dr}, {s, ds}}]

i6 : describe B

o6 = QQ[r, s, dr, ds, Degrees => {4:1}, Heft => {1}, WeylAlgebra => {{r, dr}, {s, ds}}]

i7 : rA = (describe A)#0#1#6#2#0#0#0#0

o7 = r

o7 : monoid[r, s, dr, ds, Degrees => {4:1}, Heft => {1}, WeylAlgebra => {{r, dr}, {s, ds}}]

i8 : rB = (describe B)#0#1#6#2#0#0#0#0

o8 = r

o8 : monoid[r, s, dr, ds, Degrees => {4:1}, Heft => {1}, WeylAlgebra => {{r, dr}, {s, ds}}]

i9 : rA === rB

o9 = false

i10 : hash class rA

o10 = 1044676

i11 : hash class rB

o11 = 1044700

@d-torrance d-torrance added the Core Issues involving the Core scripts. label Aug 5, 2026
@pzinn

pzinn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

yeah that's a weird one. will investigate

@pzinn

pzinn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

edited: figured it out. the modification of runLengthEncode modified the describe of a Weyl algebra -- there shouldn't be a monoid element in the description. should be an easy fix.

@seangrate seangrate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The added tests are appreciated!

d-torrance added a commit to d-torrance/M2 that referenced this pull request Aug 25, 2026
… nobody had seen

Ten rows, Macaulay2#4339 to Macaulay2#4398.  Applied on his "I approve.  Please commit/apply/push".
Two comments out, nothing closed.  Eight of the ten reproduce, the highest rate of
any batch so far.

  Macaulay2#4339  reproduces  ISC is dead at the DNS level, not just the path
  Macaulay2#4342  stands      the AI analysis missed a site, and that site is dead code
  Macaulay2#4356  reproduces  COMMENTED -- pasted input puts the whole block in history 1
  Macaulay2#4368  reproduces  check(41) fails here too; Bertini is installed
  Macaulay2#4376  reproduces  COMMENTED -- a three-line case with no garbage at all
  Macaulay2#4389  reproduces  path keeps its relative entries across the cd
  Macaulay2#4391  reproduces  3.227s, 3.184s, 3.143s -- no caching whatsoever
  Macaulay2#4392  reproduces  closing stdio makes every later prompt fail, forever
  Macaulay2#4393  reproduces  fixed in pzinn's Macaulay2#4532, still open
  Macaulay2#4398  stands      the primitive he wants already exists as sethash

Published: comments on Macaulay2#4356 and Macaulay2#4376; types on all ten; labels +package issue on
Macaulay2#4339 and Macaulay2#4391, +Interfaces on Macaulay2#4368, +Core on Macaulay2#4389 and Macaulay2#4393, +Interpreter on
Macaulay2#4392; and -bug on Macaulay2#4356, Macaulay2#4368 and Macaulay2#4376.

THE bug LABEL IS NOW A STANDING SWAP.  Doug's instruction this batch: "Everything
`bug` label should be replaced with the `Bug` type.  Same with `feature request` =>
`Feature`."  So a row carrying either label is triaged as one move, --type Bug
--rm bug, and the removal rides along in the batch approval rather than being asked
about on its own.  Recorded in README.md under "Types, not the bug and feature
request labels", with the counts that show no back-fill is needed: when the
instruction was given only 2 already-triaged rows still carried `bug` -- Macaulay2#4356 and
Macaulay2#4368, both here -- against 78 untriaged.  77 remain, all of them todo.

Macaulay2#4376 is the row that grew.  pzinn's frac(QQ[x])[y] case still produces a 603662
character entry and Doug's zero-denominator QQ, but there is a smaller one with no
frac and nothing alarming in the output: in S = QQ[x][y], mutableMatrix{{x}} *
mutableMatrix{{y}} is x^2 where the immutable product is x*y.  ring a_(0,0) is
QQ[x] and ring b_(0,0) is S, so nothing promotes to a common ring and the product
reads one variable as the other.  That is the version worth fixing against: three
lines, silently wrong, no 600KB of digits to raise the alarm.

Macaulay2#4356's mechanism is history indexing rather than positions.  locate is right
throughout; what fails is that pasted input lands entirely in history entry 1 with
the following entries empty, so code's stdio branch stacks "" for anything defined
after the first line of a block and the guard at m2/code.m2:76 fires with 0 < 1.
That is the pattern pzinn could not see -- any line after the first in a block,
which on Macaulay2Web is most of them.  Macaulay2#4351 gave `return` a position and so
triggered a lookup that used to be skipped; the history gap is older.

Macaulay2#4391 needed the reporter's own input.  A small ideal is a bad proxy -- ZZ/101[a..f]
with four random cubics went 0.168s then 0.029s, which reads either way -- so his
5.5KB ideal came out of the issue body with gh rather than being retyped, and three
successive minimalBetti calls took 3.2273s, 3.18395s, 3.14285s.  Also answered his
side question: minimalBetti over QQ does not error.

Two things Doug caught.  Macaulay2#4393's follow-up comment was drafted and then dropped:
pzinn's PR Macaulay2#4532 merges rle and runLengthEncode, so explaining the difference
between them would explain a distinction he has already deleted -- and that PR
fixes both halves of the row.  And Macaulay2#4347 was reported here as unmerged on the
strength of `gh api ... -q '.mergedAt'` returning null, which is the GraphQL
spelling of a REST field; it merged 2026-06-06.  That trap is now written up in
README.md under "Finding the commit".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Issues involving the Core scripts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runLengthEncode prefers sequences to duplicates

3 participants