
# Given a collection of automorphisms ag of poset P, and a subset V
# of relations in P, return true if V is NOT the cheapest member of
# its orbit under the action of ag.
#
# Given a fourth argument e0 = the most expensive edge of P,
# then generate the orbits of both V *and* P-V, and return true
# whenever V is not the cheapest member of *both* orbits.
#
# The V's that return true can be skipped in labeled searches.

orbitsquash:=proc(P,V,ag) local orb,new,pi,U,f,J,e,i;
  orb:={V}; new:={seq(subs(pi,V),pi=ag)} minus orb;
  while nops(new)>0 do 
    for i to nops(new) do
      if nargs>3 and member(args[4],new[i]) then
        U:=P minus new[i] else U:=new[i] fi;
      f:=`orbitsquash/first`(U minus V); J:=V minus U;
      for e in J do
        if e[1]<f[1] or (e[1]=f[1] and e[2]<f[2]) then RETURN(true) fi
      od;
    od;
    orb:={op(orb),op(new)};
    new:={seq(op(subs(pi,orb)),pi=ag)} minus orb;
  od; false
end;

# Return the most expensive edge of a nonempty set V.
# In case V is empty, return the fake edge [infinity,0].

`orbitsquash/first`:=proc(V) local e,f;
  if nops(V)>0 then f:=V[1] else RETURN([infinity,0]) fi;
  for e in V do
    if e[1]<f[1] or (e[1]=f[1] and e[2]<f[2]) then f:=e fi
  od; f
end:

