`PcGroupCode`: admit HEX string as the first argument?
Just for curiosity:
CodePcGroup and PcGroupCode are advertised for storing pc groups.
Would it not be better to use HEX strings instead of integers, since they are shorter and one can evaluate them easier than a sequence of digits?
If yes then we could extend PcGroupCode such that also a HEX string is accepted.
But then we are locked in into "the first argument is a string means hex". Do we really want that?
For example, for my extension of the small groups library, I actually store those codes Base64 encoded, which is even more compact.
Here is my naive implementation. Maybe it would be useful to add something like this to GAP (we could latter add a kernel version if we need the speed):
BASE64_CODES:="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{|";
Base64Encode := function(val)
local str, q, r;
str := "";
while val > 0 do
q := QuoInt(val, 64);
r := val - 64 * q;
Add(str, BASE64_CODES[r+1]);
val := q;
od;
return str;
end;
Base64Decode := function(str)
local val, c, d;
val := 0;
while Length(str) > 0 do
c := Remove(str); # get last "digit"
d := POSITION_SORTED_LIST(BASE64_CODES, c) - 1;
Assert(1, BASE64_CODES[d+1] = c);
val := val * 64 + d;
od;
return val;
end;
Note that there are several variants for Base64. I am actually surprised that my code uses {| as the last two values... No idea where I got that from. If we put this into GAP, I suggest we follow one of the RFCs for this. So probably +/. I also implemented no padding
Getting back to the issue at hand: I can easily write PcGroupCode(IntHexString(code), order) in my code. And then can easily replace it by PcGroupCode(Base64Decode(code), order) if I need to. These simple functions are easy to compose.
There are multiple places in the code in which information is stored in compact form through numbers or strings to make it Readable. (I think I have re-invented the wheel on this at least once.)
It would be good to have one recommended way of doing this, which is plausibly efficient, robust and fast, maybe even with some basic translation functions to the objects one actually wants (to integers, vectors, matrices, words)
@hulpke Thanks, this is the context I had in mind: The point is not so much the code that deals with the data but the way how the data are stored on files.
There are various places where data are encoded via integers or strings, CodePcGroup is one example. Another situation is the question how to store a boolean flag for all members of a (long) list of data, such as the transitive groups library; the list of booleans can be regarded as a (large) integer, and one can actually store this in different ways, as mentioned above.