Difference between revisions of "W1525 Containment"
Line 89: | Line 89: | ||
<br clear='all' /> | <br clear='all' /> | ||
=== Sets in Swift === | === Sets in Swift === | ||
Sets are useful when we want to check efficiently to determine whether an element is a member of a set AND the order of the elements in the collection doesn't matter. | |||
The most useful methods are: | |||
{| class=wikitable | |||
|- | |||
! Method | |||
! Purpose | |||
|- | |||
| {{SwiftIdentifier|contains}} | |||
| Returns true iff the element is contained in the set | |||
|- | |||
| == | |||
| Returns true iff both sets contain the same elements | |||
|- | |||
| {{SwiftIdentifier|isSubset}} | |||
| Returns true if the set contains ALL of the elements of another | |||
|- | |||
| {{SwiftIdentifier|union}} | |||
| Returns a new set which contains ALL of the elements of the original set and another | |||
|- | |||
| {{SwiftIdentifier|intersection}} | |||
| Returns a new set with only the elements that are in common to the original set and another | |||
|} | |||
== Experiment == | == Experiment == |
Revision as of 19:21, 24 January 2021
Prerequisites[edit]
Research[edit]
- Set Theory (Wikipedia)
- Set Theory for Computer Science (Glynn Winskel, University of Cambridge)
Background[edit]
Set Basics[edit]
By the 1930's, through the work of Godel, Church, Turing and others, it was realized that Set Theory relied on an even more basic concept, that of computability. Computer Science continues to be inspired by Set Theory and understanding Set Theory should facilitate your ability to think abstractly. It is, by its nature, independent of yet critical for programming.
A set is an unordered collection of objects. The objects are referred to as elements or members of the set.
Symbols | Definition |
---|---|
The empty set | |
Another way of symbolizing the empty set | |
The set containing the elements | |
is a member of the set | |
is NOT a member of the set | |
ℕ | The set of natural numbers |
ℕ0 | The set of natural numbers with zero |
ℤ | The set of integers (negative, zero, and positive) |
ℝ | The set of real numbers |
The set X is a subset of the set Y | |
The set X is NOT a subset of the set Y |
A set is termed a subset of set iff every element of is an element of . Formally:
Two sets and are equal iff every element of is an element of and vice versa. Formally:
Boolean Algebra of Sets[edit]
Assume set . The following operations are defined:
Symbols | Name | Definition |
---|---|---|
Union | ||
Intersection | ||
Complement |
Set Union[edit]
Set Intersection[edit]
Set Complement[edit]
Sets in Swift[edit]
Sets are useful when we want to check efficiently to determine whether an element is a member of a set AND the order of the elements in the collection doesn't matter.
The most useful methods are:
Method | Purpose |
---|---|
contains | Returns true iff the element is contained in the set |
== | Returns true iff both sets contain the same elements |
isSubset | Returns true if the set contains ALL of the elements of another |
union | Returns a new set which contains ALL of the elements of the original set and another |
intersection | Returns a new set with only the elements that are in common to the original set and another |
Experiment[edit]
Getting Started[edit]
Continue from the previous project; we'll be editing all of our files there. Enter into the Sources directory of the project.
john-williams@codermerlin: cd ~/Experiences/W1521/Sources/ScenesShell/
Key Concepts[edit]
Exercises[edit]
References[edit]
- Set Theory (Wikipedia)
- Set Theory for Computer Science (Glynn Winskel, University of Cambridge)