There are some:
https://fricas.org/api/SetOfMIntegersInOneToN.html
https://fricas.org/api/GrayCode.html
mabye even more ...

But in principle you only have to produce the numbers 0..2^(N-1) in binary 
form and filter (index) your set by the 1's (present), 0 absent..






On Monday, 7 April 2025 at 17:51:16 UTC+2 ra...@hemmecke.org wrote:

> 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/73f11d40-727f-48ae-96e1-e449aebd87ban%40googlegroups.com.
  • [frica... Martin Baker
    • R... 'Prof. Dr. Johannes Grabmeier' via FriCAS - computer algebra system
    • R... 'Ralf Hemmecke' via FriCAS - computer algebra system
      • ... Kurt Pagani
        • ... 'Ralf Hemmecke' via FriCAS - computer algebra system
          • ... Martin Baker
            • ... Kurt Pagani
              • ... Martin Baker

Reply via email to