How to Efficiently Handle Set Operations Without Inbuilt Functions?

AI Thread Summary
The discussion focuses on efficiently handling set operations without using built-in functions. Participants confirm the result of the operation A - (B ∪ C) as {1, y} and emphasize the importance of verifying answers independently. They discuss the application of DeMorgan's laws in set theory and suggest a straightforward approach to manually compute set differences. One participant proposes pseudocode for removing elements from set A based on elements in sets B and C, highlighting the efficiency of iterating through each set separately. The conversation underscores the balance between using formulas and practical methods in set operations.
chwala
Gold Member
Messages
2,825
Reaction score
413
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
Have you heard of DeMorgan's laws?
 
  • Like
Likes chwala
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 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 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 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 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 Hall and chwala
Back
Top