0
Let S = { trigon, tetragon , pentagon , ... ,... } is a set of polygons

How to calculate intersection of subsets of (every element actually) Powerset(S)

Powerset(S) =[ {} , {trigon} , {tetragon} , {pentagon} , {trigon, tetragon} , {trigon,pentagon} ,......]

for i in Powerset(S)
  find intersect(i)

I need really fast algorithm, is there any solution? intersection funtion is so expansive and therefore I want minimize this

Are dynamic programming solutions suitable for this?

enter image description here

shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39
XLVII
  • 31
  • 5
  • 1
    The powerset of S is the set of all subsets of S. It is not the intersection of all subsets of S. The intersection of all subsets is always empty. – Stef Dec 08 '21 at 11:16
  • Are you looking to write the algorithm yourself, or do you want a standard function from a standard library for some language? – Stef Dec 08 '21 at 11:16
  • For instance, in python, search for "powerset" on that page: https://docs.python.org/3/library/itertools.html#itertools-recipes and for C++, see this related question: [How to write C++ version of Python powerset function?](https://stackoverflow.com/questions/22898119/how-to-write-c-version-of-python-powerset-function) – Stef Dec 08 '21 at 11:19
  • A recursive formula for the powerset is: `powerset(S u {a}) == {s u {a} for s in powerset(S)} u powerset(S)` where `u` means union, and S is a set that does not contain a (so that S u {a} has exactly one element more than S). You can use this recursive formula to write a function in your favourite language (using recursion or iteration). – Stef Dec 08 '21 at 11:21
  • @Stef why did you suggest recursive formula – XLVII Dec 08 '21 at 11:37
  • Why would I not suggest it? – Stef Dec 08 '21 at 11:37
  • An equivalent formulation of that formula is: let a be an element of S; then `powerset(S) = { subsets that contain a } u { subsets that do not contain a }` – Stef Dec 08 '21 at 11:39
  • @Stef is for Dynamic programing? – XLVII Dec 08 '21 at 11:39
  • There is no real need for dynamic programming here. A simple iterative or recursive function that repeatedly applies the formula will work. – Stef Dec 08 '21 at 11:40
  • @Stef just to be sure, I don't want to find powerset, I want powerset elements to intersect within themselves – XLVII Dec 08 '21 at 11:42
  • In that case, please explain in more detail what you want. Also give an explicit example. If S = {a, b, c}, then what result do you want? So far, I can't understand what you mean. What are you intersecting with what? – Stef Dec 08 '21 at 11:45
  • @Stef added a picture – XLVII Dec 08 '21 at 11:52
  • I don't unerstand the picture. Are you trying to build a graph? – Stef Dec 08 '21 at 11:52
  • @Stef no it's just lattice notation, S= {a,b ,c}--->1= intersect({}) ,2= intersect(a) , ........ , 5 = intersect( a,b ) , ............ 8 = intersect(a,b,c) – XLVII Dec 08 '21 at 11:55
  • What does `intersect` mean in that context? Please give a very concrete example. What is `intersect(a)`? – Stef Dec 08 '21 at 11:58
  • Wait... Is that a geometry problem? Is the fact that your elements are called polygons relevant? – Stef Dec 08 '21 at 11:59
  • @Stef yes it is , it does not matter what it is , intersect( a, b,c ) = intersect( intersect ( a,b), c) – XLVII Dec 08 '21 at 12:02
  • What do you mean in _'I want powerset elements to intersect within themselves'_...? – CiaPan Dec 08 '21 at 12:02
  • `i` is a set. It is not a set of sets, so there doesn't seem to be any interpretation of `intersect(i)` that makes sense. – Matt Timmermans Dec 08 '21 at 13:51
  • @MattTimmermans yes i is a set, this set has elements and at the end of day intersection( x € i) – XLVII Dec 08 '21 at 14:00
  • how do you intersect a tetragon with a pentagon? – Matt Timmermans Dec 08 '21 at 14:03
  • @MattTimmermans it is polytope, there is a polyhedron library – XLVII Dec 08 '21 at 16:29
  • Oh... you want a *geometric* intersection, not a set intersection. That's the kind of thing you want to make clear in the question :-) – Matt Timmermans Dec 08 '21 at 17:44

0 Answers0