gap icon indicating copy to clipboard operation
gap copied to clipboard

Disallow duplicate named generators when constructing magmas, semigroups, groups, etc

Open wilfwilson opened this issue 4 months ago • 7 comments

To me it seems like doing something like FreeGroup("x", "x"); can only possibly lead to potential confusion, I can't see a use case for it and I think it should be disallowed. But I'm open to contrary opinions.

To add:

  • [x] generatorNames option for pc groups
  • [x] FreeMagma
  • [x] FreeMagmaWithOne
  • [x] FreeSemigroup
  • [x] FreeMonoid
  • [x] FreeGroup
  • [x] FreeAlgebra
  • [x] FreeAlgebraWithOne
  • [x] FreeAssociativeAlgebra
  • [x] FreeAssociativeAlgebraWithOne
  • [x] FreeLieAlgebra
  • [x] FreeBand and FreeInverseSemigroup: https://github.com/semigroups/Semigroups/pull/1118

Plus:

  • [ ] Add tests for everything
  • [ ] Update manual entries for everything
  • [ ] Update manual examples

wilfwilson avatar Sep 05 '25 17:09 wilfwilson

It seems there are manual examples that explicitly use duplicate generators, see for example the part of the manual titled "Comparison of Associative Words" (?Comparison of Associative Words), which gives the example:

gap> f:= FreeGroup( "a", "b", "b" );;
gap> gens:= GeneratorsOfGroup(f);
[ a, b, b ]
gap> gens[2] = gens[3];
false
gap> x:= gens[1]*gens[2];
a*b
gap> y:= gens[2]/gens[2]*gens[1]*gens[2];
a*b
gap> x = y;
true
gap> z:= gens[2]/gens[2]*gens[1]*gens[3];
a*b
gap> x = z;
false

Which demonstrates that x <> z, i.e. a * b <> a * b.

We can also see that AssignGeneratorVariables has the following behaviour with duplicate generator names:

gap> G := FreeGroup("a", "b", "b");
<free group on the generators [ a, b, b ]>
gap> AssignGeneratorVariables(G);
#I  Global variable `b' is already defined and will be overwritten
#I  Assigned the global variables [ a, b, b ]

wilfwilson avatar Sep 05 '25 18:09 wilfwilson

I am tempted to forbid it, because I find it hard to imagine someone is using this on purpose, and hasn't just made a typo and is confusing themselves.

ChrisJefferson avatar Sep 08 '25 07:09 ChrisJefferson

I agree with @ChrisJefferson. I think the manual example quoted above should be changed.

My guess is that the idea of this manual example is to demonstrate that words which look equal need not be equal. However, artificially choosing the same name for different generators is not a good example for that lesson, comparing elements from different free objects would make more sense.

ThomasBreuer avatar Sep 15 '25 08:09 ThomasBreuer

I agree with @ThomasBreuer and @ChrisJefferson

james-d-mitchell avatar Sep 16 '25 07:09 james-d-mitchell

I'd be fine with this as well.

fingolfin avatar Oct 04 '25 01:10 fingolfin

I'll try to get it finished soon.

wilfwilson avatar Oct 10 '25 21:10 wilfwilson

I agree with @ChrisJefferson, @james-d-mitchell and @fingolfin. I doubt, I can find a use-case to use same name for two different generators.

limakzi avatar Nov 25 '25 18:11 limakzi