1
$\begingroup$

I am having trouble writing the Mathematica code to prove this answer. I was able to derive the answers but through trial and error, ideally I want to derive them through examination of correct code.

subsetQ[A_, B_] := Module[{i},
Catch[Do[If[! MemberQ[B, i], Throw[False]], {i, A}]; Throw[True]]]

S1 = Subsets[Subsets[{}]]

MemberQ[S1, {}]
MemberQ[S1, {{}}]
MemberQ[S1, {{{}}}]
subsetQ[S1, {{}, {{{}}} }]

enter image description here

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Feb 27 '16 at 1:44
  • $\begingroup$ You are more likely to obtain help, if your question shows that you have tried to solve this problem yourself. $\endgroup$ – bbgodfrey Feb 27 '16 at 1:46
  • 2
    $\begingroup$ Look up Subsets[] as well. $\endgroup$ – J. M. will be back soon Feb 27 '16 at 1:46
  • $\begingroup$ Thank you for the welcome and apologies if my first question is not great. I looked over the Subsets[] documentation but still cannot figure out where I am causing error. $\endgroup$ – Michael Givan Feb 27 '16 at 3:21
2
$\begingroup$

Rather than using MemberQ, you should use the built-in SubsetQ for your testing:

S1 = Subsets[Subsets[{}]]  (* {{}, {{}}} *)

SubsetQ[S1, {}]            (* True  *)
SubsetQ[S1, {{}}]          (* True  *)
SubsetQ[S1, {{{}}}]        (* True  *)
SubsetQ[S1, {{}, {{{}}}}]  (* False *)

The documentation explains that SubsetQ tests for non-strict subsets, and also yields True if its arguments are equivalent. Notice a few differences in behavior between SubsetQ and MemberQ:

list = {a, b, c};

SubsetQ[list, {a, b, c}]  (* True  *)
MemberQ[list, {a, b, c}]  (* False *)

SubsetQ[list, {}]         (* True  *)
MemberQ[list, {}]         (* False *)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.