Message Boards Message Boards

0
|
649 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Determine the partial sets' complements

Posted 6 months ago

I gave up trying to determine the partial sets' complements so that the outcome would be {{P2,P3,P4},{P1,P4}}

In[193]:= TT := {{{P1}, {P2, P3}}} XX := {P1, P2, P3, P4}

In[195]:= MapThread[Complement, {{Flatten[XX]}, {Flatten[TT]}}, 1]

Out[195]= {{P4}}
POSTED BY: Alyasaa Jasim
Posted 6 months ago

Generally the "threading" functions expect things to have the same shape. If I understand your situation, you have one set, XX that you want to pair with each of two other sets, contained in TT. Since the shapes aren't the same (length 1 versus length 2), it will be awkward and convoluted to get threading to work. You could just map:

XX = {P1, P2, P3, P4};
TT = {{P1}, {P2, P3}};
Map[Complement[XX, #] &, TT]

(* {{P2, P3, P4}, {P1, P4}} *)

You don't need SetDelayed (i.e. :=), just Set (i.e. =) works fine. Also, you had an extra layer of List in TT.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract