doesn't it suffice to construct all subsets from 0..n-1 for you?

(9) -> for k in 0..6 repeat for i in 0..binomial(6,k)-1 repeat print subSet(6,k,i)
   []
   [0]
   [1]
   [2]
   [3]
   [4]
   [5]
   [1, 0]
   [2, 0]
   [2, 1]
   [3, 0]
   [3, 1]
   [3, 2]
   [4, 0]
   [4, 1]
   [4, 2]
   [4, 3]
   [5, 0]
   [5, 1]
   [5, 2]
   [5, 3]
   [5, 4]
   [2, 1, 0]
   [3, 1, 0]
   [3, 2, 0]
   [3, 2, 1]
   [4, 1, 0]
   [4, 2, 0]
   [4, 2, 1]
   [4, 3, 0]
   [4, 3, 1]
   [4, 3, 2]
   [5, 1, 0]
   [5, 2, 0]
   [5, 2, 1]
   [5, 3, 0]
   [5, 3, 1]
   [5, 3, 2]
   [5, 4, 0]
   [5, 4, 1]
   [5, 4, 2]
   [5, 4, 3]
   [3, 2, 1, 0]
   [4, 2, 1, 0]
   [4, 3, 1, 0]
   [4, 3, 2, 0]
   [4, 3, 2, 1]
   [5, 2, 1, 0]
   [5, 3, 1, 0]
   [5, 3, 2, 0]
   [5, 3, 2, 1]
   [5, 4, 1, 0]
   [5, 4, 2, 0]
   [5, 4, 2, 1]
   [5, 4, 3, 0]
   [5, 4, 3, 1]
   [5, 4, 3, 2]
   [4, 3, 2, 1, 0]
   [5, 3, 2, 1, 0]
   [5, 4, 2, 1, 0]
   [5, 4, 3, 1, 0]
   [5, 4, 3, 2, 0]
   [5, 4, 3, 2, 1]
   [5, 4, 3, 2, 1, 0]

Am 07.04.25 um 17:14 schrieb Martin Baker:
Is there any code in the FriCAS library to generate a power set from a set?
I could not find any so I wrote my own (see below). I probably need
custom code anyway to sort and filter the results.
My problem is that the only way I could work out how to do this is to
customise the list.spad code like this:
https://github.com/martinbaker/fricasAlgTop/blob/topology/list.spad#L295
Is there some way I can make a more standalone version of the following
code?
What I would like to do is replace 'S' with 'Type' but I don't think
that would work would it?

      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)

      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)))

      powerSet(j:List(S)):List List S ==
        powerSetFiltered(j,(x)+-> true)

--
Mit freundlichen Grüßen

Johannes Grabmeier

Prof. Dr. Johannes Grabmeier,
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Fax: +49-(0)-991-2979592

--
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/5e3c1129-99e1-4a9d-a46e-21102625c31b%40grabmeier.net.
  • [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