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

Wrong result in IsIntegralRing #3975

Closed
olexandr-konovalov opened this issue Apr 21, 2020 · 8 comments · Fixed by #5817
Closed

Wrong result in IsIntegralRing #3975

olexandr-konovalov opened this issue Apr 21, 2020 · 8 comments · Fixed by #5817
Labels
kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them

Comments

@olexandr-konovalov
Copy link
Member

Reported by @grahamknockillaree:

gap> R:=SmallRing(4,3);;
gap> IsIntegralRing(R);
true
gap> ShowMultiplicationTable(R);
*   | 0*a a   2*a -a
----+----------------
0*a | 0*a 0*a 0*a 0*a
a   | 0*a a   2*a -a
2*a | 0*a 2*a 0*a 2*a
-a  | 0*a -a  2*a a

The problem is in the line

gap/lib/ring.gi

Line 704 in 86c4135

for k in [i+1..Length(elms)] do

which should be

for k  in [i..Length(elms)]

to check the diagonal as well.

Thank you for reporting it - I will make a PR tomorrow.

@Stefan-Kohl
Copy link
Member

In that example, the zeros don't appear on the diagonal:

gap> IsIntegralRing(Integers mod 6);
true

@olexandr-konovalov
Copy link
Member Author

Thanks for another example @Stefan-Kohl - will look tomorrow, and will use this opportunity to create a proper test for IsIntegralRing. It shown zero coverage at https://codecov.io/gh/alex-konovalov/gap/src/master/lib/ring.gi.

olexandr-konovalov pushed a commit to olexandr-konovalov/gap that referenced this issue Apr 22, 2020
@olexandr-konovalov
Copy link
Member Author

Aha, the reason for Integers mod 6 is different: the answer is triggered by this method:

InstallTrueMethod( IsIntegralRing,
    IsUniqueFactorizationRing and IsNonTrivial );

olexandr-konovalov pushed a commit to olexandr-konovalov/gap that referenced this issue Apr 22, 2020
The first one fixes an off-by-one error causing missing the case
when zero appears in the diagonal in the multiplication table.

The second one removes incorrect true method wrongly claiming
that a non trivial unique factorisation ring is an integral ring.

Closes gap-system#3975.
@olexandr-konovalov olexandr-konovalov added the kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them label Apr 22, 2020
@fingolfin
Copy link
Member

In the Integers mod 6 example, this comes from the implication:

InstallTrueMethod( IsIntegralRing,
    IsUniqueFactorizationRing and IsNonTrivial );

This is also a regression from GAP 4.10. (Since I mostly touched the zmodnz code, most likely this will turn out to be my fault sigh).

So let's bisect it: Create file IntegralRing.tst with content

gap> IsIntegralRing(Integers mod 6);
false

Now start the bisect:

cp etc/bisect.sh /tmp
git bisect bad master
git bisect good stable-4.10
git bisect run /tmp/bisect.sh IntegralRing.tst

Result after a few minutes: 0f9c104 is the first commit (of course as predicted by me, yay :-). Now gotta see what's wrong with it...

olexandr-konovalov pushed a commit to olexandr-konovalov/gap that referenced this issue Apr 22, 2020
This fixes an off-by-one error causing missing the case
when zero appears in the diagonal in the multiplication table.

Closes gap-system#3975.
olexandr-konovalov pushed a commit to olexandr-konovalov/gap that referenced this issue Apr 22, 2020
It was added in commit 0f9c104 and
caused IsIntegralRing wrongly return 'true' e.g. for Integers mod 6,
as reported in gap-system#3975.
@grahamknockillaree
Copy link

grahamknockillaree commented Apr 22, 2020

A related issue is

gap> ShowMultiplicationTable(SmallRing(5,2));

*   | 0*a a   2*a 3*a -a 
----+--------------------
0*a | 0*a 0*a 0*a 0*a 0*a
a   | 0*a a   2*a 3*a -a 
2*a | 0*a 2*a -a  a   3*a
3*a | 0*a 3*a a   -a  2*a
-a  | 0*a -a  3*a 2*a a  

gap> IsField(SmallRing(5,2));
false

IsField is a filter, so I guess this is not a bug. But it could be confusing to a user.

@olexandr-konovalov
Copy link
Member Author

@grahamknockillaree yes, this isn't a bug (one could get a similar confusion with IsGroup for objects that mathematically are groups, but are not constructed as groups in GAP).

@wilfwilson
Copy link
Member

wilfwilson commented Apr 8, 2021

The following method introduced in 0f9c104 (the commit @fingolfin bisected the problem to) is inconsistent with GAP:

InstallTrueMethod(IsEuclideanRing, IsZmodnZObjNonprimeCollection and
     IsWholeFamily and IsRing);

In particular, the GAP documentation for IsEuclideanRing begins with:

A ring R is called a Euclidean ring if it is an integral ring and...

Therefore, as things are documented, IsEuclideanRing should return false for Z/nZ with composite n, not true. But as @alex-konovalov seems to have found when writing commit olexandr-konovalov@24b10d2, simply removing this TrueMethod causes GAP to not load.

In more detail, the result of removing the TrueMethod is that this method fails to install:

#############################################################################
##
#M  EuclideanDegree( <R>, <n> )
##
##  For an overview on the theory of euclidean rings which are not domains,
##  see Pierre Samuel, "About Euclidean rings", J. Algebra, 1971 vol. 19 pp. 282-301.
##  http://dx.doi.org/10.1016/0021-8693(71)90110-4

InstallMethod( EuclideanDegree,
    "for Z/nZ and an element in Z/nZ",
    IsCollsElms,
    [ IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing, IsZmodnZObj and IsModulusRep ],
    function ( R, n )
      return GcdInt( n![1], Characteristic( n ) );
    end );

because there is no longer a matching declaration. This is because EuclideanDegree is declared for [ IsEuclideanRing, IsRingElement ], but IsZmodnZObjNonprimeCollection and IsWholeFamily and IsRing no longer implies IsEuclideanRing. Indeed, the documentation for EuclideanDegree says:

The ring R must be a Euclidean ring

Now, I understand from the helpful message from @fingolfin that his new methods use the notion of Euclidean from http://dx.doi.org/10.1016/0021-8693(71)90110-4, which is more general.

Therefore, either this broader notion of Euclidean needs a different name in GAP, or we need to agree to change the behaviour and documentation of GAP to use this the broader notion.

@wilfwilson
Copy link
Member

Sorry, I missed the linked pull request #3976!

@fingolfin fingolfin added this to the GAP 4.13.0 milestone Mar 27, 2023
@fingolfin fingolfin modified the milestones: GAP 4.13.0, GAP 4.14.0 Oct 17, 2023
@fingolfin fingolfin removed this from the GAP 4.14.0 milestone Oct 13, 2024
fingolfin pushed a commit to fingolfin/gap that referenced this issue Oct 15, 2024
This fixes an off-by-one error causing missing the case
when zero appears in the diagonal in the multiplication table.

Closes gap-system#3975.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them
Projects
None yet
5 participants