Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranges: improve printing and conversion to strings #4625

Merged

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Aug 2, 2021

  • Add tests for printing ranges & converting them to strings
  • Improve String/ViewString/PrintString for ranges

The diff between the first and second commit shows what changed.

Perhaps we should have similar tests for other library objects?

This patch has been motivated by the CI failure I observed here: https://github.com/gap-packages/fr/pull/38/checks?check_run_id=3160342361

@fingolfin fingolfin added topic: library release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Aug 2, 2021
@fingolfin fingolfin force-pushed the mh/unify-range-printing-viewing branch from 52ba080 to dfb7a43 Compare August 2, 2021 22:55
PrintString: [ 0 .. 2 ]
String: [ 0 .. 2 ]
gap> TestPrintRangeRep([0,2..4]);
ViewObj: [ 0, 2 .. 4 ]
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we could go one step further and also print [ 0, 2 .. 4 ] as [ 0, 2, 4 ]...

Copy link
Contributor

Choose a reason for hiding this comment

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

The input [ 0, 2, 4 ] does not produce an object in IsRangeRep, whereas [ 0, 2 .. 4 ] creates such an object.
In this sense, I would not be in favour of this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the documentation does not make any claim that the representation is preserved by reentering the output of Print; just that an equal object is returned. So both print outputs conform to the documentation.

In any case, always printing ranges as ranges certainly is also an option; the main motivation for this PR really is to make it behave consistently in one way or the other.

Copy link
Member

Choose a reason for hiding this comment

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

I would support this kind of change, if you want to make it.

@fingolfin fingolfin requested a review from ThomasBreuer August 4, 2021 13:33
@fingolfin
Copy link
Member Author

Some tests here failing, which will be easy enough to fix, but it'd be nice to first get feedback on the general idea.

DisplayString: <object>
ViewString: [ 0, -1 ]
PrintString: [ 0, -1 ]
String: [ 0, -1 ]
Copy link
Member Author

@fingolfin fingolfin Aug 4, 2021

Choose a reason for hiding this comment

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

Note: perhaps we do want this to produce [ 0, -1 .. -1 ] in a few cases; and likewise, [ 0 .. 1 ] instead of [ 0, 1 ]. But then IMHO these two should behave consistenly: either both kinds of ranges of length 2 are shown "as range", or both are shown "as lists". Also, of course ViewString and ViewObj should be consistent, and likewise PrintString and PrintObj. (Well... and DisplayString, but I did not even try to fix that in this PR)

@fingolfin fingolfin force-pushed the mh/unify-range-printing-viewing branch from dfb7a43 to a3c09ff Compare August 4, 2021 13:39
@wilfwilson
Copy link
Member

I don't have time to properly review at the moment, but I do like the general idea from what I can get at a glance. However, I worry that it suffers from the same problem as #4050, i.e. breaks the tests of various packages, which will make it annoying to merge.

Copy link
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

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

Let me try to summarize what this pull request changes.

  • For ranges of length two, Display, PrintObj, PrintString, and String now show the two entries separated by a comma; up to now, the .. notation was used. The output of ViewObj (using a comma) was not changed. ViewString uses a comma before and after the change, but the hints \> and \< that were present before the change have now disappeared.
  • For ranges with at least three elements, now there is a special ViewString method that uses the .. notation; up to now, all entries of the range were listed. I regard the pull request as a bugfix in this respect. (One could discuss whether the hints \> and \< should be inserted.)

From the viewpoint of consistency w.r.t. the operations in question, now ranges with at least three elements are shown as ranges if they store that they are ranges, and ranges of length two are not shown as ranges. (Ranges of length at most one do not store that they are ranges.)

Concerning the impact of the change on package tests, I have not found differences in the basic tests for my packages CTblLib, AtlasRep, and CTBlocks. Perhaps there are some differences in the tests of other packages, but I think that the changes proposed in #4050 (mentioned by @wilfwilson ) cause significantly more trouble.

Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

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

I've looked at this in more detail now and I do support it the changes, in particular the consistency and the showing length-two ranges like [1..2] as [1,2]. I would support further such changes in this direction (e.g. [1,3..5] being [1,3,5]).

@ThomasBreuer raises a good point about the \> and \< hints.

I agree with @ThomasBreuer that this PR should not be anyway near as disruptive as #4050, but it causes at least some problems. Running the standard tests of Digraphs and Semigroups with this PR I get:

  • Digraphs: 6 failures in 2 of 16 files
  • Semigroups: 11 failures in 3 of 67 files

It should be easy to fix such problems by suppressing output. Hopefully it will be easy enough to detect affected packages.

Note that the CI is currently not passing.

PrintString: [ 0 .. 2 ]
String: [ 0 .. 2 ]
gap> TestPrintRangeRep([0,2..4]);
ViewObj: [ 0, 2 .. 4 ]
Copy link
Member

Choose a reason for hiding this comment

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

I would support this kind of change, if you want to make it.

@@ -270,7 +270,7 @@ false

# IsReesMatrixSemigroup: for a Rees matrix subsemigroup with generators, 1
gap> R := ReesMatrixSemigroup(SymmetricGroup(2), [[(1,2)]]);
<Rees matrix semigroup 1x1 over Sym( [ 1 .. 2 ] )>
<Rees matrix semigroup 1x1 over Sym( [ 1, 2 ] )>
Copy link
Member

Choose a reason for hiding this comment

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

There are quite a few of these kinds of changes in Semigroups and Digraphs, (almost?) all of which involve Sym( [ 1 .. 2 ] ) becoming Sym( [ 1, 2 ] )

@fingolfin fingolfin force-pushed the mh/unify-range-printing-viewing branch from a3c09ff to d554eca Compare January 9, 2022 14:10
Copy link
Member

@olexandr-konovalov olexandr-konovalov left a comment

Choose a reason for hiding this comment

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

Would be nice to have - will impact package tests, but with the advent of https://github.com/gap-system/PackageDistro/ that can be then systematically addressed. Some packages may need more work to adapt examples to pass in both new and old GAP versions.

@fingolfin fingolfin force-pushed the mh/unify-range-printing-viewing branch from d554eca to 9a2e32e Compare August 2, 2022 12:22
... to match ViewObj and Display.

As a result, Display, PrintObj, DisplayString, PrintString and String
now all behave the same for ranges, while ViewObj and ViewString differ.
This is probably quite surprising to people, but changing it one way or
the other will affect packages, so for now let's play it safe and only
address the "obvious" bugs.
@fingolfin fingolfin force-pushed the mh/unify-range-printing-viewing branch from 9a2e32e to de03049 Compare August 3, 2022 08:49
@fingolfin
Copy link
Member Author

fingolfin commented Aug 3, 2022

I have now revised the changes in this PR, going in a somewhat different direction: instead of trying to align ViewObj with PrintObj and Display, I've opted to only "fix" ViewString for ranges to produce a string corresponding to the output of ViewObj. Also, I've now added a DisplayString method matching Display.

The result is still a bit odd because now the View* methods (still) behave differently from the Display* and Print* methods. But at least one inconsistency was resolved, and I don't think there will be any conflicts with packages. If someone wants to resolve the remaining inconsistency one day, be my guess, but I don't think it's all that important.

@fingolfin fingolfin merged commit b4e599e into gap-system:master Aug 3, 2022
@fingolfin fingolfin deleted the mh/unify-range-printing-viewing branch August 3, 2022 20:29
Copy link

@pedritomelenas pedritomelenas left a comment

Choose a reason for hiding this comment

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

I wonder if lists with three elements like [0,2..4] should be “printed” as [0, 2, 4] instead of [0, 2 .. 4]

@fingolfin
Copy link
Member Author

"Should"? Dunno.... "Could"? Sure. But any such change has a cost, you need to at least update all packages whose test suites depend on the printing. IMHO it is not worth the trouble

@pedritomelenas
Copy link

Sure, I should have used could.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants