What is that called in set theory that can be used in programming to make set A equal to set B by adding to and subtracting from B the differences?

52 Views Asked by At

What is that called in set theory that can be used in programming to make set B equal to set A by (1) adding to set B what set A has but set B does not have, and (2) removing from set B what set A does not have, but set B does have?

I think it's similar to the concept of a symmetric difference, not not alike.

Step (1) would be to add (A-B) to B.

Step (2) would be to subtract (B-A) from B.

I think it could be expressed like this:

B_prime = B + (A-B) - (B-A)

B_prime = B + A - B - B + A

B_prime = - B + A + A

If I call B_prime the resulting state of what was originally B, B_prime should be expressed as the differences between the sets plus the intersection of the sets, like so:

B_prime = (intersection between A and B) + (A-B)

B_prime = (intersection between A and B) + A - B

In code, B_prime would actually be the resulting state of B after the process is complete.

However, I am not able to make the steps I outlined agree with the way I think the expression should be expressed in terms of B_prime. How do I connect the steps I outlined with the way I think the result should be as expressed as B_prime.

Is there a name for the entire process I described? If there is a name for it than it is a likelihood that there is a function in any language that does exactly just that, and I wouldn't need to write my own code to do this.