Skip to content

Use IsZero instead of comparing with 0*x in the library - #6708

Merged
fingolfin merged 2 commits into
gap-system:masterfrom
lgoettgens:lg/iszero
Oct 8, 2026
Merged

fingolfin merged 2 commits into
gap-system:masterfrom
lgoettgens:lg/iszero

Conversation

@lgoettgens

Copy link
Copy Markdown
Member

Replace 40 checks of the form x = 0*x, x <> 0*x or x = 0*y in the library by IsZero( x ).

IsZero is shorter and avoids building a zero object just for the comparison. Its generic method does the same elm = 0*elm comparison, and some representations have faster methods.

🤖 Created with the help of Claude Code (Opus 5.5)

Replace checks of the form `x = 0*x`, `x <> 0*x` and `x = 0*y` by
`IsZero( x )`. This is shorter, avoids building a zero object just
for the comparison, and lets representations with a dedicated
`IsZero` method use it.

Assisted-by: Claude Code (Opus 5.5)
@lgoettgens lgoettgens added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Oct 8, 2026

@james-d-mitchell james-d-mitchell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like a good change to me

@fingolfin

Copy link
Copy Markdown
Member

CI fails, strange:

  testing: ~/work/gap/gap/tst/testinstall/meataxe.tst
  ########> Diff in ~/work/gap/gap/tst/testinstall/meataxe.tst:353
  # Input is:
  Length( MTX.BasisModuleHomomorphisms( M, M2 ) );
  # Expected output:
  4
  # But found:
  Error, Record Element: '<rec>.basisVectors' must have an assigned va\
  lue
  ########
      3263 ms (710 ms GC) and 459MB allocated for meataxe.tst

@james-d-mitchell

Copy link
Copy Markdown
Contributor

I've seen this recently in the ci for Semigroups also, which I think is unrelated to the changes in this pr. I'll try to post the link when I'm back at my computer

@fingolfin
fingolfin enabled auto-merge (squash) October 8, 2026 20:12
@fingolfin
fingolfin merged commit 4a88154 into gap-system:master Oct 8, 2026
31 checks passed
@lgoettgens
lgoettgens deleted the lg/iszero branch October 8, 2026 20:56
@james-d-mitchell

Copy link
Copy Markdown
Contributor

I've seen this recently in the ci for Semigroups also, which I think is unrelated to the changes in this pr. I'll try to post the link when I'm back at my computer

So, here's the related failure in the Semigroups CI:

https://github.com/semigroups/Semigroups/actions/runs/37783273881/job/113331490255?pr=1235

from

semigroups/Semigroups#1235

The error is identical to the one @fingolfin reported here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements 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.

3 participants