Why would you make your code so complicated? I would simply write:
T ==> Integer pwrset(s: List T) : List List T == empty? s => [[]] ps: List List T := pwrset rest s t: T := first s tps := [cons(t, p) for p in ps] concat(ps, tps) powerSet(l: List T): List List T == sort((x,y)+->#x<#y, pwrset sort l) On 4/7/25 17:14, Martin Baker wrote:
localPowerSets(j:List(S),filter:List(S)->Boolean): List(List S) == empty? j => list [] Sm := localPowerSets(rest j,filter) Sn: List List S := [] for x in Sm repeat if filter(x) then Sn := cons(reverse cons(first j, x),Sn) append(Sn, Sm)
Why do you use "reverse" here? Can you tell a reason for this filter function?
gradeAndOrder(a:List S,b:List S) : Boolean == if #a < #b then return true if #a > #b then return false for ia in a for ib in b repeat if S has OrderedSet then if ia < ib then return true if ia > ib then return false false powerSetFiltered(j:List(S),filter:List(S)->Boolean):List List S == map(reverse,sort(gradeAndOrder,localPowerSets(j,filter)))
Again, why reverse?
powerSet(j:List(S)):List List S == powerSetFiltered(j,(x)+-> true)
If you want this "stand-alone" then you have to write a package with parameter T around the above code.
Ralf -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/c6cb6999-112f-44fc-b495-b1534982375b%40hemmecke.org.