1
$\begingroup$

I hve a set S consisting of four terms.

S = {a b, c d, c e a, a b c, b c d}

I need a code to delete terms within the set S when the following condition is met: delete any terms containing a two-element term also in the set.

For example

$a\,b \subset a\,b\,c,\ c\,d \subset b\,c\,d$

then we delete a b c and b c d, reducing S to {a b,c d,c e a}

Please help.

$\endgroup$
  • $\begingroup$ But a b contains a two-element term also in the set (a b). Why didn't you delete that? Also: never use an upper-case letter to denote anything in Mathematica as it may conflict with the naming conventions in the language. $\endgroup$ – David G. Stork Jul 11 '17 at 1:19
  • $\begingroup$ Are the a, b, c, etc. supposed to commute? $\endgroup$ – JEM_Mosig Jul 11 '17 at 2:37
1
$\begingroup$

It's unclear what the Mathematica form of the set is. I will assume that the set elements are just symbols:

DeleteDuplicates[
    {ab,cd,cea,abc,bcd},
    StringContainsQ[SymbolName[#2],SymbolName[#1]]&
]

{ab, cd, cea}

Update to new form of $S$

DeleteDuplicates[
    {a b, c d, c e a, a b c, b c d},
    Denominator[#2/#1]==1&
]

{a b, c d, a c e}

This assumes that shorter symbols are ordered before longer symbols.

$\endgroup$
2
$\begingroup$

Build a graph firstly

g = RelationGraph[StringContainsQ[##] && UnsameQ[##] &, ToString /@ S]

Mathematica graphics

The sink vertex is what you are after

GraphComputation`SinkVertexList[g]

{a c e, c d, a b}

$\endgroup$
1
$\begingroup$

This

S = {a b, c d, c e a, a b c, b c d};
sets = List @@ S; 
supersets[s_] := Select[sets, Intersection[#, s] == s && Length[#] > 2 &];
tobedeleted = Flatten[Map[supersets, Select[sets, Length[#] == 2 &]], 1];
DeleteCases[sets, Alternatives @@ tobedeleted]

gives you {a b, c d, a c e}

Test this carefully before you depend on it

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy