GAP: Function to iterate through Coxeter monoids to test which produce a finite Origami monoid

 

# the function will try each monoid for arg4 seconds before moving on to the next. The relevant function is TestCoxeterOrigami
NumberCombos:=function(m,n,lists,iteration)
	local i,j,list,list2,lists2;
	lists2:=[];
	if iteration<m+1 then
		if lists=[] then
			for i in [0..n] do
				Add(lists2,[i]);
			od;
		else
			for list in lists do
				for i in [0..3] do
					list2:=ShallowCopy(list);
					Add(list2,Random([0..n]));
					Add(lists2, list2);
				od;
			od;
		fi;
	else
		return lists;
	fi;
	j:=iteration+1;
	return NumberCombos(m,n,lists2,j);
end;
			
CreateCoxeterInput := function(numGenerators, n, p)
	local generators, inputs, a, b, c, d, i, j, k, y, z, blank, range, ranges, pos, rel, numlists, blanker, numbers;

	# Generate generator names
	generators := List([1..numGenerators], i -> Concatenation("g", String(i)));
	# Create relations
	blank := [];
		for a in generators do
			for b in generators do
				if not a=b then
					rel:=[a,,b];
					Add(blank,rel);
				fi;
			od;
		od;
	for c in blank do
		for d in blank do
			if c[1]=d[3] and c[3]=d[1] then
				pos:=Position(blank,d);
				Remove(blank,pos);
			fi;
		od;
 	   od;
	inputs:=[];
	numlists:=NumberCombos(Size(blank),n,[],1);;
	numbers:=[];
	for i in [1..p] do
		j:=Random(numlists);
		Add(numbers,j);
	od;
	for k in numbers do
		blanker:=StructuralCopy(blank);
		for z in blanker do
			pos:=Position(blanker,z);
			z[2]:=k[pos];
		od;
	Add(inputs,blanker);
	od;
	return inputs;
end;

# Main program to iterate through Coxeter Monoids and apply OrigamiMonoidIdemp
TestCoxeterOrigami := function(numGenerators, n, p, timeout)
    local inputs, coxeterMonoid, origamiMonoid, tStart, tempFile, command, result, input, i;

    inputs := CreateCoxeterInput(numGenerators, n, p);

    for i in [1..Length(inputs)] do
        input := inputs[i];
        Print("Testing input ", input, "\n");

        Print("Creating CoxeterMonoid...\n");
        coxeterMonoid := CoxeterMonoid(input);
        if coxeterMonoid = fail then
            Print("Error: CoxeterMonoid creation failed for input ", input, "\n");
            continue;
        fi;
        Print("CoxeterMonoid created successfully for input: ", input, "\n");

        Print("Applying OrigamiMonoidIdemp...\n");
        origamiMonoid := OrigamiMonoidIdemp(coxeterMonoid);
        if origamiMonoid = fail then
            Print("Error: Failed to apply OrigamiMonoidIdemp for input ", input, "\n");
            continue;
        fi;
        Print("OrigamiMonoidIdemp applied successfully for input: ", input, "\n");

        Print("Checking finiteness with timeout...\n");
        tempFile := Concatenation("temp_finiteness_", String(i), ".g");
PrintTo(tempFile, Concatenation(
    "Mapper := function(word, arg)\n",
    "    local i, u, v, w, prod, monoid;\n",
    "    w := ExtRepOfObj(word);\n",
    "    prod := [];\n",
    "    if IsMonoid(arg) then\n",
    "        monoid := arg;\n",
    "        for i in [1..(Length(w)/2)] do\n",
    "            u := monoid.(w[2*i-1])^(w[2*i]);\n",
    "            Add(prod, u);\n",
    "        od;\n",
    "    elif IsSemigroup(arg) then\n",
    "        monoid := arg;\n",
    "        for i in [1..(Length(w)/2)] do\n",
    "            u := monoid.(w[2*i-1])^(w[2*i]);\n",
    "            Add(prod, u);\n",
    "        od;\n",
    "    else\n",
    "        for i in [1..(Length(w)/2)] do\n",
    "            u := arg[(w[2*i-1])]^(w[2*i]);\n",
    "            Add(prod, u);\n",
    "        od;\n",
    "    fi;\n",
    "    v := Product(prod);\n",
    "    return v;\n",
    "end;\n\n",
    "OrigamiMonoidIdemp := function(monoid)\n",
    "    local gens, mgens, rels, newrels, mrels, agens, bgens, arels, brels, abgens, bagens, doublegens, doublerels, w, free, left, right, abrels, barels, M, rws, freeaddrules, creatingrules, i, j, n, generatorMap, fgens, pos, gens0, mapped, commrels;\n\n",
    "    if not IsFpMonoid(monoid) then\n",
    "        Print(\"Not a monoid. Perhaps try OrigamiSemigroup.\\n\");\n",
    "        return fail;\n",
    "    fi;\n\n",
    "    gens := [];\n",
    "    for i in [1..Size(GeneratorsOfMonoid(monoid))] do\n",
    "        Add(gens, monoid.(i));\n",
    "    od;\n",
    "    n := Size(gens);\n",
    "    rels := RelationsOfFpMonoid(monoid);\n",
    "    newrels := [];\n",
    "    for i in rels do\n",
    "        if not i[1] = i[2] then\n",
    "            Add(newrels, i);\n",
    "        fi;\n",
    "    od;\n",
    "    rels := newrels;\n\n",
    "    agens := [];\n",
    "    bgens := [];\n",
    "    for i in [1..Length(gens)] do\n",
    "        Add(agens, Concatenation(\"a\", String(i)));\n",
    "        Add(bgens, Concatenation(\"b\", String(i)));\n",
    "    od;\n",
    "    mgens := Concatenation(agens, bgens);\n",
    "    free := FreeMonoid(mgens);\n",
    "    generatorMap := rec();\n",
    "    fgens := GeneratorsOfMonoid(free);\n",
    "    agens := [];\n",
    "    for i in [1..n] do\n",
    "        Add(agens, free.(i));\n",
    "    od;\n",
    "    bgens := [];\n",
    "    for i in [n+1..Size(GeneratorsOfMonoid(free))] do\n",
    "        Add(bgens, free.(i));\n",
    "    od;\n\n",
    "    arels := [];\n",
    "    for i in rels do\n",
    "        left := Mapper(i[1], agens);\n",
    "        right := Mapper(i[2], agens);\n",
    "        Add(arels, [left, right]);\n",
    "    od;\n\n",
    "    brels := [];\n",
    "    for i in rels do\n",
    "        left := Mapper(i[1], bgens);\n",
    "        right := Mapper(i[2], bgens);\n",
    "        Add(brels, [left, right]);\n",
    "    od;\n",
    "    mrels := [];\n",
    "    UniteSet(mrels, arels);\n",
    "    UniteSet(mrels, brels);\n\n",
    "    doublerels := [];\n",
    "    doublegens := [];\n",
    "    abgens := [];\n",
    "    bagens := [];\n",
    "    for i in agens do\n",
    "        pos := Position(agens, i);\n",
    "        w := i * bgens[pos];\n",
    "        Add(abgens, w);\n",
    "    od;\n",
    "    for i in bgens do\n",
    "        pos := Position(bgens, i);\n",
    "        w := i * agens[pos];\n",
    "        Add(bagens, w);\n",
    "    od;\n",
    "    UniteSet(doublegens, abgens);\n",
    "    UniteSet(doublegens, bagens);\n",
    "    for i in mrels do\n",
    "        left := Mapper(i[1], doublegens);\n",
    "        right := Mapper(i[2], doublegens);\n",
    "        Add(doublerels, [left, right]);\n",
    "    od;\n\n",
    "    commrels := [];\n",
    "    for i in agens do\n",
    "        for j in bgens do\n",
    "            if not Position(agens, i) = Position(bgens, j) then\n",
    "                left := j * i;\n",
    "                right := i * j;\n",
    "                Add(commrels, [left, right]);\n",
    "            fi;\n",
    "        od;\n",
    "    od;\n\n",
    "    rels := [];\n",
    "    arels := Set(arels);\n",
    "    brels := Set(brels);\n",
    "    doublerels := Set(doublerels);\n",
    "    commrels := Set(commrels);\n",
    "    UniteSet(rels, arels);\n",
    "    UniteSet(rels, brels);\n",
    "    UniteSet(rels, doublerels);\n",
    "    UniteSet(rels, commrels);\n\n",
    "    M := free / rels;\n",
    "    return M;\n",
    "end;\n\n",
    "CoxeterMonoid := function(D)\n",
    "    local gens, rels, i, j, k, fm, f, n;\n",
    "    gens := [];\n",
    "    rels := [];\n",
    "    for i in D do\n",
    "        Add(gens, i[1]);\n",
    "        Add(gens, i[3]);\n",
    "    od;\n",
    "    gens := Set(gens);\n",
    "    fm := FreeMonoid(gens);\n",
    "    for i in D do\n",
    "        j := Position(gens, i[1]);\n",
    "        k := Position(gens, i[3]);\n",
    "        n := Int((i[2])/2);\n",
    "        if n = i[2]/2 then\n",
    "            Add(rels, [(fm.(k) * fm.(j))^(n), (fm.(j) * fm.(k))^(n)]);\n",
    "        else\n",
    "            Add(rels, [(fm.(k) * fm.(j))^(n) * fm.(k), (fm.(j) * fm.(k))^(n) * fm.(j)]);\n",
    "        fi;\n",
    "        Add(rels, [fm.(j)^2, fm.(j)]);\n",
    "        Add(rels, [fm.(k)^2, fm.(k)]);\n",
    "    od;\n",
    "    rels := Set(rels);\n",
    "    f := fm / rels;\n",
    "    return f;\n",
    "end;\n\n",
    "coxeterMonoid := CoxeterMonoid(", String(input), ");\n",
    "if coxeterMonoid = fail then\n",
    "    Print(\"Failed to create CoxeterMonoid.\\n\");\n",
    "    #return;\n",
    "fi;\n\n",
    "origamiMonoid := OrigamiMonoidIdemp(coxeterMonoid);\n",
    "if origamiMonoid = fail then\n",
    "    Print(\"Failed to create OrigamiMonoidIdemp.\\n\");\n",
    "    #return;\n",
    "else\n",
    "    if IsFinite(origamiMonoid) then\n",
    "        Print(\"Finite\\n\");\n",
    "        Print(\Size(origamiMonoid)\);\n",
    "    else\n",
    "        Print(Size(origamiMonoid), \"\\n\");\n",
    "    fi;\n",
    "fi;\n",
    "#return;"
));


command := Concatenation("timeout ", String(timeout), "s gap -q --nointeract -r ", tempFile);
Exec(command);
Print("\n\n");

        Exec(Concatenation("rm ",String(tempFile)));
    od;

    Print("Finished testing all inputs.\n");
end;

Comments

Popular posts from this blog

GAP: Alternate function to create finitely presented Coxeter monoid of a given Coxeter matrix

GAP: Function to create Origami monoid of given finitely presented monoid with all idempotent generators