Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implementing set theory operations in php

How to implement set theory operations in pure php?

like image 614
Thomas Vincent Avatar asked Aug 17 '10 02:08

Thomas Vincent


People also ask

What are the 4 set operations?

There are four main set operations which include set union, set intersection, set complement, and set difference.

What is set operation with example?

If there are two sets A and B, then the difference of two sets A and B is equal to the set which consists of elements present in A but not in B. It is represented by A-B. Example: If A = {1,2,3,4,5,6,7} and B = {6,7} are two sets.

What is set theory explain different set operations?

The symbol ∪ is employed to denote the union of two sets. Thus, the set A ∪ B—read “A union B” or “the union of A and B”—is defined as the set that consists of all elements belonging to either set A or set B (or both).

How do you add two sets in math?

Addition of sets A and B, referred to as Minkowski addition, is the set in whose elements are the sum of each possible pair of elements from the 2 sets (that is one element is from set A and the other is from set B). Set subtraction follows the same rule, but with the subtraction operation on the elements.


2 Answers

Which operations are you looking for? What are you trying to accomplish?

In PHP an array is (imperfectly) analogous to a set, and PHP has array_intersect, array_merge (union), and array_diff (complement) functions built in. There's also array_uintersect and array_udiff for handling complex objects whose comparisons are not so straightforward.

Is there further functionality you need?

like image 57
Jordan Running Avatar answered Sep 28 '22 08:09

Jordan Running


Probably you'll already saw those links:

http://jamietalbot.com/2010/02/04/set-operations-in-php/

http://oreilly.com/catalog/progphp/chapter/ch05.html

like image 24
Strae Avatar answered Sep 28 '22 08:09

Strae