Repository navigation
Bracket a right operand that opens with a set difference or a mod - #2768
Open
Rafael-SOWNet wants to merge 1 commit into
Open
Rafael-SOWNet wants to merge 1 commit into
Rafael-SOWNet wants to merge 1 commit into
Conversation
A union printed a union on its right flat, and a product a product or a
quotient, because both operators are associative. But `\` shares a level
with `\/`, and `mod` with `*` and `/`, and the grammar folds each level to
the left, so flat printing re-associates every operator along the
operand's left edge, not only the associative one. `A \/ ((B \ C) \/ D)`
printed `A \/ B \ C \/ D` and read back as `((A \/ B) \ C) \/ D`; Simplify's
`{ pi } \/ { -1, 1 } \ [-2; +oo) \/ QQ` named a set without pi; and
`2 * ((3 mod 2) * 4)` printed `2 * 3 mod 2 * 4`, which is 0, not 8.
Entity.OpensWithANonAssociativeOperator walks the operand's unbracketed
left edge and says whether it reaches a `\` or a `mod`; Unionf's Stringize
and Latexize and Mulf's Stringize bracket such an operand. Operands made
only of unions, or of products and quotients, still print flat. Mulf's
LaTeX flattens products and brackets each \bmod factor already.
Generated nestings, seeds 11 and 12: 4000 set expressions (\/, /\, \ over
symbols, finite sets, intervals, conditional sets and QQ), 1000 under `in`
and `provided`, 2000 LaTeX, 4000 of *, /, mod, + and - with unary minus.
Read back as a different expression on master: 56 set, 32 LaTeX, 45
arithmetic; on this branch: 0.
Fixes #2758
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2768 +/- ##
==========================================
+ Coverage 86.70% 86.71% +0.01%
==========================================
Files 346 346
Lines 77113 77130 +17
Branches 22699 22705 +6
==========================================
+ Hits 66859 66884 +25
+ Misses 5533 5529 -4
+ Partials 4721 4717 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2758
Covers the same case as the draft #2764 by
NginxL(a right union operand whose leftmost descendant is a set difference), plus the same defect one level up the grammar: a right operand of*that opens with amod.Cause
\/and*are associative, so their printers print a right operand of their own level flat. But\shares the level of\/, andmodthe level of*and/, and the grammar folds each level to the left. Printing flat re-associates every operator along the operand's unbracketed left edge, not only the associative one, so an operand that opens with\ormodcame back with the outer operator inside it. The printers only bracketed an operand that was a\or amod.Change
Entity.OpensWithANonAssociativeOperatorwalks the operand's unbracketed left edge (Unionf.Left;Mulf.Multiplier,Divf.Dividend; stopping at a-xprefix, at a lower priority, or at a node printed asdomain(...)) and says whether it reaches a\or amod.Unionf.Stringize,Unionf.LatexizeandMulf.Stringizebracket such an operand. A right operand made only of unions, or only of products and quotients, still prints flat, asAnAssociativeOperatorPrintsFlatAndKeepsItsValuepins.Mulf.Latexizeflattens products and already brackets every\bmodfactor after the first, so it needed no change.ToSympyprints sets as calls (sympy.Union(...)), so it is unaffected.BREAKING-CHANGES.mdentry with before/after measured on a build of each.Before / after (measured)
578680eedA \/ ((B \ C) \/ D)A \/ B \ C \/ D(reads back as((A \/ B) \ C) \/ D)A \/ (B \ C \/ D){ 1 } \/ (({ 2 } \ { 1 }) \/ { 3 }){ 1 } \/ { 2 } \ { 1 } \/ { 3 }(={ 2, 3 }){ 1 } \/ ({ 2 } \ { 1 } \/ { 3 })({ -1, 1 } \ [-2; +oo)) \/ (QQ \/ { pi }){ pi } \/ { -1, 1 } \ [-2; +oo) \/ QQ(no pi){ pi } \/ ({ -1, 1 } \ [-2; +oo) \/ QQ)A \/ ((B \ C) \/ D)A \cup B \setminus C \cup DA \cup \left(B \setminus C \cup D\right)2 * ((3 mod 2) * 4)2 * 3 mod 2 * 4(= 0, not 8)2 * (3 mod 2 * 4)x * ((y mod z) / w)x * y mod z / wx * (y mod z / w)-((y mod z) * w)-y mod z * w(=((-y) mod z) * w)-(y mod z * w)Sweep
Generated nestings, printed with
Stringize(andLatexize, translated back), parsed, compared as entities; a difference that is only re-association of\/,/\,+,*is counted as fine. Seeds 11 and 12:\/,/\,\over symbolsQQ(judged by membership at 11 points)inandprovided*,/,modwith unary minus (judged by value)*,/,mod,+,-No row got worse. The workspace
roundtripharness (5000 random expressions) reports identically on master and the branch; it does not nest set operators, which is why it never saw this.Tests and harnesses
StringizeRoundTripTest(ASCII and Unicode): the nestings above as exact round trips, as values, and Simplify's answers from the issue reading back as themselves;LatexTestpins the bracketed and the still-flat LaTeX.IntegralAnswerCacheTest.AnIntegralWithNoAnswerStillFinishesQuickly, a wall-clock test (38 s at load average ~30); it passes alone (9/9 in 4 s), and failed the same way in the same session on fix: preserve leading set difference in right unions #2764's build.Syntax.md's precedence table is unchanged and still true), so docsamples is unaffected.Timing
The walk runs only when the right operand is at the operator's own precedence level, and goes down the left edge of the operand once; ordinary printing is unchanged.
🤖 Generated with Claude Code