How to Efficiently Handle Set Operations Without Inbuilt Functions?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 2K views
chwala
Gold Member
Messages
2,843
Reaction score
428
Homework Statement
This is my original question; Given ##A=[1,2,x,y]## ##B=[2,x,z,m]## ##C=[4,5]##, then find
##A-(BUC)##
Relevant Equations
set theory
ok we shall have ##(A-B)∩(A-C)= [1,y]∩[1,2,x,y]=[1,y]## correct?
 
Physics news on Phys.org
chwala said:
Homework Statement:: This is my original question; Given ##A=[1,2,x,y]## ##B=[2,x,z,m]## ##C=[4,5]##, then find
##A-(BUC)##
Relevant Equations:: set theory

ok we shall have ##(A-B)∩(A-C)= [1,y]∩[1,2,x,y]=[1,y]## correct?
Correct. But it concerns me that you seem unable to check your answers yourself. That is a skill that is just as important to learn as anything else.
 
  • Like
Likes   Reactions: chwala
WWGD said:
Have you heard of DeMorgan's laws?
Yes that's what I used...##M-(B∪Q)=(M-B)∩(M-Q)##
 
Last edited:
  • Like
Likes   Reactions: WWGD
FactChecker said:
Correct. But it concerns me that you seem unable to check your answers yourself. That is a skill that is just as important to learn as anything else.
I am able to check...I ask because I may want a different perspective from what I know...I am always learning...cheers
 
chwala said:
I am able to check...I ask because I may want a different perspective from what I know...I am always learning...cheers
My perspective would be that if you want a simple answer to this, you do the following:

a) Write down the elements of the set ##A##: ##1, 2, x, y##.

b) Write down the elements of ##B \cup C##: ##2, x, z, m, 4, 5##

c) Go through the set ##B \cup C## one element at a time and delete these elements from the list in set ##A##.

1d) That gives the answer ##A - (B \cup C) = \{1, y\}##

If you want to verify De Morgan's law by using this as an example, then fine. But, don't lose sight of the simple fact that ##A - (B \cup C)## means things that are in ##A## with anything that is in either ##B## or ##C## removed.
 
  • Love
  • Like
Likes   Reactions: Mark44 and chwala
Yes, it's a good think not to rely only on big formulas , but what if you have similar with a large collection of sets? It becomes a nightmare to do a specific example.
 
  • Like
Likes   Reactions: chwala
WWGD said:
Yes, it's a good think not to rely only on big formulas , but what if you have similar with a large collection of sets? It becomes a nightmare to do a specific example.
If I were coding this, without using inbuilt set operations, then I would do it either the way described; or, not bother with the union at all, but just go through ##B## and ##C## separately and delete elements from ##A##. My first step wouldn't be the form the sets ##A - B## and ##A - C##.

For example, pseudocode for ##X = A - (B_1 \cup B_2 \dots \cup B_n)##:

Create set ##X = A##
For ##k = 1## to ##n##:
Remove any element in ##B_k## from ##X##
(or, ##X = X - B_k## for short)
Loop
Print ##X##
 
  • Like
Likes   Reactions: Hall and chwala