/*
Independant procedures for testing conjugacy functions (table 12.8).
*/

bClass := func<G, x |
    (x notin Class(G, x))
	or ({y^z : y in Class(G, x), z in Generators(G)} ne Class(G, x))
>;
cClass := func<G, x | Class(G, x) ne x^G>;

eClass := function(G, x)
    h := {};
    k := {x};
    while h ne k do
	h := k;
	k join:= {y^z : y in k, z in Generators(G)};
    end while;
    return h ne Class(G, x);
end function;

// For small classes.
dConj := func<G, x, y | IsConjugate(G, x, y) ne (y in Class(G, x))>;

cConj := function(G, x, y)
/*
This is really to test the conjugacy element:
an error will be listed if non-conjugate x & y are used.
*/
    b,e := IsConjugate(G, x, y);
    return not b or (x^e ne y);
end function;

bClsMd := function(g)
/*
Check some conditions on the classes (medium sized groups).
*/
    cl := Classes(g);
    og := Order(g);
    for i := 1 to #cl do
	ind := Index(g, Centralizer(g, cl[i][3]));
	if (ind ne cl[i][2]) or (Order(cl[i][3]) ne cl[i][1]) then
	    return true;
	end if;
	og -:= cl[i][2];
    end for;
    return og ne 0;
end function;

bClsSm := function(G)
/*
Now for small groups (using class)
*/
    cl := Classes(G);
    og := {x : x in G};
    for i := 1 to #cl do
	c := Class(G, cl[i][3]);
	if (#c ne cl[i][2]) or not (c subset og) then
	    return true;
	end if;
	og diff:= c;
    end for;
    return og ne {};
end function;

// PANIC: applicable to p-groups only.
// Tests a modulus condition on number of classes.
bNclasses := func<G |
    (
	NumberOfClasses(G)
	    - FactoredOrder(G)[1][1]^(FactoredOrder(G)[1][2] mod 2)
	    - FactoredOrder(G)[1][2] div 2 * (FactoredOrder(G)[1][1]^2-1)
    ) mod (FactoredOrder(G)[1][1]^2-1) * (FactoredOrder(G)[1][1]-1) ne 0
>;

dNclasses := func<G | NumberOfClasses(G) ne #Classes(G)>;

bExponent := func<G | {x ^ Exponent(G) : x in Generators(G)} ne {Id(G)}>;

eExponent := function(G)
/*
Calculate and compare exponent.
*/
    c := Classes(G);
    e := 1;
    for i := 1 to #c do
	e := LCM(e, c[i][1]);
    end for;
    return e ne Exponent(G);
end function;
