Project

General

Profile

Design #1409

myTestIsPrimary & Co. : fix design

Added by Anna Maria Bigatti about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Category:
Safety
Target version:
Start date:
03 Feb 2020
Due date:
% Done:

100%

Estimated time:
6.66 h
Spent time:

Description

I spent a few hours fixing a bug in

  bool SparsePolyRingBase::IdealImpl::myTestIsPrimary_0dim() const

Now I can claim it was just due to my bad design of returning a bool:
this way I have actually fooled myself (as author+maintainer) in believing this just returns a bool. Instead, the main effect of this function is setting the primary flag.
This is quite common in C++ (changing+returning) but it is more dangerous than useful.

Change this into void, test, and fix all its companions.


Related issues

Related to CoCoALib - Design #924: FlagManager for bool/bool3 flagsNew2016-09-19

Related to CoCoALib - Feature #899: IsMaximal, IsPrimary for IDEAL (in cocoalib)Closed2016-06-27

Related to CoCoALib - Bug #1411: IsPrimary sometimes wrongClosed2020-02-03

Related to CoCoALib - Bug #1411: IsPrimary sometimes wrongClosed2020-02-03

Related to CoCoA-5 - Support #1387: John's visit Feb 2020Closed2020-01-07

History

#1 Updated by Anna Maria Bigatti about 4 years ago

  • Related to Design #924: FlagManager for bool/bool3 flags added

#2 Updated by Anna Maria Bigatti about 4 years ago

  • Related to Feature #899: IsMaximal, IsPrimary for IDEAL (in cocoalib) added

#3 Updated by Anna Maria Bigatti about 4 years ago

This was the error, found by Ashkan Nikseresht (nice feedback! thanks!)

/* */ K::=ZZ/(2);
/* */ Use S::=K[a,b,x,y];
/* */ al:=a^2+a+1;
/* */ be1:=b^2 +(a)*b +(1);
/* */ J:=ideal(al, be1, (x-a)^2,(y-b^2));
/* */ IsPrimary(J);
true
/* */ Iz:=Elim([a,b],J);
/* */ Iz;
ideal(x^4 +x^2 +1,  x^2*y +y^2 +1,  y^3 +x^2 +y^2 +1)
/* */ Use R::=K[x,y];
/* */ phi:=PolyAlgebraHom(S,R,[0,0,x,y]);
/* */ I1:=ideal(apply(phi,gens(Iz)));
/* */ I1;
ideal(x^4 +x^2 +1,  x^2*y +y^2 +1,  y^3 +x^2 +y^2 +1)
/* */ radi:=Radical(I1);
/* */ IsMaximal(radi);
true
/* */ IsPrimary(I1);
false

#4 Updated by Anna Maria Bigatti about 4 years ago

I added the test to exbugs.cocoa5

#5 Updated by John Abbott about 4 years ago

  • Status changed from New to In Progress
  • % Done changed from 20 to 50

I fixed this as well. Anyway, we can merge when I'm in Italy (hopefully).

I agree that the use of myAssignPrimaryFlag etc. is risky because one can easily make a mistake...
How to find a safer design?

#6 Updated by Anna Maria Bigatti about 4 years ago

  • Related to Bug #1411: IsPrimary sometimes wrong added

#7 Updated by John Abbott about 4 years ago

  • Related to Bug #1411: IsPrimary sometimes wrong added

#8 Updated by John Abbott about 4 years ago

  • Description updated (diff)

The corrected code should be in 0.99700.
We should discuss the design when I'm in Genoa. Maybe we can finish this for 0.99700?

Changing return type to void is probably reasonable; but then we may want to change the name slightly.

#9 Updated by John Abbott about 4 years ago

#10 Updated by John Abbott about 4 years ago

I like the suggestion to change the fn to void. Still we should discuss it when I'm there.
Also we should look to see if there are other similar fns whose design should be changed.

As a safety feature we could put CoCoA_ASSERT(!IsUncertain3(myPrimaryFlag)) after the call.

Even "better" we could implement as follows: main fn calls the one that does the work, then
makes the assertion. While this is safer (since you cannot forget to write the assertion
after every call), it seems to complicate the impl more than I'd like.

As a compromise, we could put assertions just before every return in the fn which actually does the work (and hope that we do not forget one).

#11 Updated by John Abbott about 4 years ago

  • Target version changed from CoCoALib-0.99800 to CoCoALib-0.99700

#12 Updated by Anna Maria Bigatti about 4 years ago

  • Target version changed from CoCoALib-0.99700 to CoCoALib-0.99800
  • % Done changed from 50 to 90

Fixed all functions myTest... so that they return void.
Now the compiler should help if something is not done properly (returned, instead of assigned).

Code looked a bit prettier before, but I found other similar mismatches while updating the code!

John Abbott wrote:

As a safety feature we could put CoCoA_ASSERT(!IsUncertain3(myPrimaryFlag)) after the call.

Even "better" we could implement as follows: main fn calls the one that does the work, then
makes the assertion.

I actually called CoCoA_ASSERT_ALWAYS (with comment // paranoia2020) in IsPrime, IsRadical, ...

#13 Updated by John Abbott about 4 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100
  • Estimated time set to 6.66 h

Appears to work now. Closing.

#14 Updated by Redmine Admin almost 4 years ago

  • Target version changed from CoCoALib-0.99800 to CoCoALib-0.99710

Also available in: Atom PDF