CSU CS220 Exam 1 prep
(recap) set 1. features 2. what are the two ways of set initiation in python 3. methods 4. set theroy operations 5. set index starts with?
1. unordered, unique, mutable 2. nums1 = set([1, 2, 3]) nums2 = { 7, 8, 9 } 3. len(aSet) set1.update(set2) # add elements in set2 to set1 aSet.add(value) set.remove(value) set.pop() # removing a random value set.clear() # remove all 4. newSet = set1.intersection(set_a, set_b, set_c...) # returning a new set of the shared items between set1 and other sets newSet = set1.union(set_a, set_b, set_c...) # all elements newSet = set1.difference(set_a, set_b, set_c...) # unique in set1 newSet = set1_a.symmetric_difference(set_2) # unique in set1 or set2 5. 1
set subtraction law
A - B = A ∩ B(Bar)
A x B will not be the same as B x A, unless
A = B, or either A or B is empty A × ∅ = ∅
function
A function f that maps elements of a set X to elements of a set Y, is a subset of X × Y such that for every x ∈ X, there is exactly one y ∈ Y for which (x, y) ∈ f. --if not exactly one y for each x, or not all x are used, then not well-defined f: X → Y / f(x) = y
disjoint
A ∩ B = ∅
function equality
Equal if have same domain, target, and f(x) = g(x) for every element in domain
T or F: ∅ ⊂ A for any A
F, as A must != ∅
inverse
If not p, then not q ¬p → ¬q
contrapositive
If not q, then not p ¬q → ¬p
converse
If q, then p q → p
is f(x) = x^2 − 2 a complete definition
No, range and target should be specified
(recap) types for collections in python
Sequence types string, list, and tuple set type for set The only mapping type in Python is the dict type
T of F: in a set, element type can be different
T
set intersection
The intersection of two sets is the set of all the elements that are common to both sets. The intersection of A and B is written as A⋂B and includes those elements that are in set A and in set B. If A = {a, b, c, d, e} and B = {a, e, i, o, u}, then A⋂B = {a, e}
set union
The union of two sets is the set of every element that is in either or both sets. The union of sets A and B is written as A⋃B and includes those elements in either set A, set B, or both. If A = {a, b, c, d, e} and B = {a, e, i, o, u}, then A⋃B = {a, b, c, d, e, i, o, u}
function composition
Using the output from one function call as the input to another. f and g are two functions, where f: X → Y and g: Y → Z. The composition of g with f, denoted g ο f, is the function (g ο f): X → Z, such that for all x ∈ X, (g ο f)(x) = g(f(x))
geometric sequence
a sequence in which each term is found by multiplying the previous term by the same number a, ar,ar2,...,arn,...
Cartesian product
a set of pairs (x, y) of elements from two sets X and Y. A x B = { (a, b) : a ∈ A and b ∈ B } If A = {1, 2, 3}, then A × ∅ = ∅
sequence
a special type of function in which domain is a consecutive set of integers
range
actual outputs, subset of Y
proposition
an argument that is logically true of false (or unknown) --in English, typically declarative sentences, can't be questions or commands
arithmetic sequences
an=a1+(n-1)d
conjunction
and, ∧
exponential
b is base and b != 1, x is exponent
operator precedence
calculation order: quantifiers, not, and, or, → , ↔
set builder notation
characterizing by the property its elements satisfy ex., O = {x: x is an odd positive interger less than 100}
domain
elements in set X, inputs
biconditional
if and only if, p ↔ q return true if p = q
contradiction
if the proposition is always false, regardless of the truth value of the individual propositions that occur in it
tautology
if the proposition is always true, regardless of the truth value of the individual propositions that occur in it
bijective
injective and surjective
log example, starting with n chocolates, dividing the chocolotes into two halves and keep one half, the times k needed to reach 1 chocolate left is ?
log2n if keep the larger half, then ceiling(log2n), if keep the smaller half, then floor(log2n)
inverse of exponential is called
logarithm
floor function
maps a real number to the nearest integer downwards
ceiling function
maps a real number to the nearest integer upwards
contingency
neither tautology nor contradiction
set complement
not in A but in U, = U - A
injective
one-to-one, one y mapping only one x In proof: if y1 = y2, then x1 = x2
comparing the size of domain and target for one-to-one, onto, and bijective
one-to-one: domain <= target onto: domain >= target bijective: domain = target
inverse of a function
only if f: X → Y is a bijection, then f-1 = { (y, x) : (x, y) ∈ f } how to get f-1(x): let y = f(x), switch y and x, find y
surjective
onto, range = target, all target elements are used In proof: for every y ∈ Y , there is a (well-defined) x = sth (figure out x) ∈ X such that f(x) = y --prove Y, prove x = sth, prove X, prove f(x) = y
disjunction
or (inclusive) --in English, ppl often use exclusive or, p ⊕ q
identity function
output = input IA : A → A, IA(a) = a Let f: A → B be a bijection. Then f-1 ο f = IA and f ο f-1 = IB --IA is starting from A
conditional proposition / conditionals
p → q, p implies q, p only if q, the proposition p is called the hypothesis, and the proposition q is called the conclusion --think of the circumstance of p = true and q = true as a contract, the only way to break the contract is when p = true and q = false p → q ≡ ¬p ∨ q
set partition
partitioning of elements of some universal set A into a collection of disjointed subsets. Thus, each element must be in exactly one subset. For all i, Ai ⊆ A. For all i, Ai ≠ ∅ A1, A2, ...,An are pairwise disjoint. A = A1 ∪ A2 ∪ ... ∪ An
logarithm
properties: logb(xy) = logbx + logby logb(x/y) = logbx - logby logb(x^y) = ylogbx logcx = logbx / logbc
target
set Y, possible outputs
set identity
set caculations / equations involving sets that are true for ALL sets
logically equivalent
statements with the same truth values, regardless of the truth values of their individual propositions p ≡ q
roster notation
the elements of a set are listed between braces
cardinality
the number of elements in a set, |aSet|
power set
the set of all subsets of a set ex. A = { 1, 2, 3 }, then: P(A) = { ∅, { 1 }, { 2 }, { 3 }, { 1, 2 }, { 1, 3 }, { 2, 3 }, { 1, 2, 3 } } remember to include the ∅ in the front! P(ø) = {ø}
set difference
unique in A A - B, what's left in A after substracting the intersection subtraction is not associative
symmetric difference
unique in A + unique in B A ⊕ B = (A-B) U (B-A) = (A U B) - (A ⋂ B) symmetric difference operation is associative: (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)
strictly increasing
whenever x1 < x2, then f(x1) < f(x2)
name x and y: A binary string is a string whose alphabet is {x, y}
x = 0 y = 1
negation
¬p --translate English negation: "It's not true that..."
The empty string is usually denoted by the symbol __
λ
∧, ∨, ¬
∧: and, ∨: or, ¬: not