Logic Sets Counting
Lecture Notes
University
Copyright By PowCoder代写 加微信 powcoder
In computer science , we are
interested
in collections o f
collections
can take many forms :
[” ” [a”b” ]] hello 42 ‘ e
a list w/in
An image might be stored a s a 3 dimensional array height ✗ width xrgb
÷:::÷::÷÷÷÷;)
the microscope Notice how .
for red , green , and blue .
centralized
collections of data .
of data and query languages (S Q L)
to ask questions of
the data are built
the concepts of set
” Relational
I n mathematics w e want to
about numbers and
properties
n’ isan even#ifand
A bit m o re formally :
n’ is even → n iseven
predicates
Ynez: even(ri)→ even(n
Direct Proof
showqfollow#
Assume ✗ is an arbitrary even #
2k for some KEZI
== So ✗ 2 ( 2k)”
i. ✗2 is even
But pay=p→of A
= 2(2k2-12k)
= 2m 1- I m = ZKZ-12k c- 21
S o math involves
properties ( predicates ) even
Graphically
membership
I might represent or non – membership
with a diagram . : DIAGRAM
This circle
natural # s that are
encompasses
” Universe ”
Prime(X) neither T or F
Prime (7) E. True Prime (iz) :
connection between
predicates
Predicates
define membership in a
This suggest a n underlying deep connection:
Consider :
knows only CS
pictures .
set of all students
( domain )
double majors are
students and English students so its ok (valid ) if
charlie knows some
majors . The diagram makes
solution more
thx Charlie
a) → cscx)
contrapositive :
th – cscx) → – Charlie(x
if ” you’re
→ char CHARLIE ¥¥¥¥÷÷÷
set. But the
values of ✗
we could say : HARLRE = {✗ c- student /
Definition
set is a n unordered of – distinct objects .
collection
5= {0000, 0001 9999} 4digitpins , ,….
Sz= {red,blue, green,yellow}
= 9 blue , green , yellow , red
Commonsets
natural # s
= {- – – , -2, -1,0, 1, 2, . . . } integers
{P/q/PEZ, qc-21, go-to} rationals
Inhere I element
In = {0,1, 2, . .
– n – }i integers mod n ,
0={} empty
builder Notation
condition o n v }
£21 , 1×1<5 }
-4, -3,2,-1,0,I,2,3,4}
( Its easier to the rules rather
just define Than
enumerating
• Cardinality : The s iz e of the set 1st = " size " A the set
= # of elements
be finite o r infinite
membership
set is a collection of elements .
3C-5 (3 is an elementofs)
(7 is not an element
U = universe of possible
1,2,3..-. ,10}
or {✗c- Z / ✗ =2k where kid}
A= "evens" = {✗/✗c-V.✗=even}
{2,4 , 6 , 8 , co }
B = "s5" = {✗ I✗c- U , Xes}
to be able
about the sizes
" 1.*. and 2-1 #s
c o nIt a i n l e t t e r s t w o -1
a) A and B are disjoint if
subset of A
element TB is an element
- Aset Proper
B is a n d A contains
t w o -1 # s They
Definitions
elements in
o v e r ☒l a p )
operations
={✗/✗EAor ✗c-B}
= {2,4 6,8 10 } AUB = {1,2, 3.4,5> , , 6,8, 10}
{ 1,2 3,415 } ,
=repetitions no
AMB= {✗/✗EAand✗c-B}
c) c⇒ : A-={x /✗c- u and ✗¢A}
TB = {6,7 , 8,9, 10 }
Setdifferene
A- B= {x/✗c-AandX_¢B}
= { 6,8 , 10 }
difference
in exactly I set
✗ c- B and ✗ f.A } LA B) u (B- A)
= (AUB)- (AnB) ÷:÷:÷
1,3,S>6,8,10}
Set operations o n multiple
An(BOC) (ANB)UC
= Logical EV
Equivalence
Equivalence
And all the usual laws
equivalence apply
-(PnQ)= -PV
ATB = A- u
– IPVQ) = – P n
AU /Bnc) = (AuB)n (AUc)
= (ANB)U(Arc)
An01=0AU01= A
Does Rachlin’s
(pnqnr) ✓ (pnqn- r)=pnq
(PNQNR ) U (PNQNÑ )
ll subsets A powensets-X.FI
PCA) setof of
e.g, A={a,b,e}
{a,b}, {a,c}, {b.c}, {a ,b, c }
Can w e generate this systematically ?
We enumerated all the
0 – element subsets
I – element subsets
2- element
each subset with a bit
string : { §
000 100 010
So clearly / P(A) 1=21^-1
whatis P(8)?
10/1=0 I @(A) 1=1 = 2 =
Remember :
Power set always contains sets as .
How many graphs are there on vertices ✓ = {A.B.C, D, E }
1–4 =14(£ = to
AB AC AD AE BC BD BE CD CE DE
:I1llllllll
10I0I0I0I0
each pair (u,v)
w e decide whether
Include an edge , so we have
.2. choices
2—-i -z=2/0==1024
g) Cartesian
Back in HS
in the Cartesian
you learned to plane
plot things
iR-R-kx.gl/xc-Ryc-iR }
A✗B= {IX.g)/✗c-AandyEB}
e.g. A – – {1,2 , 3}
{(1)a), (I,b), (2)a), C2,b),
(3e) 13b)-}
(i.a) =/ (a , 1). Order matters.
Similarly ,
= {(a , 1), (a.2)> (a.3), (b)1), (b.2), 1b$
b G.b) 12,b) (3.b)
. 1A✗B/=/A//
Generalize to multiple
A X B ✗ a = {(X,g, -2 ) / ✗c- A ,gEB, 2- c- ¢
/AXB✗a/ =/Al. /BI. KI
: -..- wemighthave”A✗Azx ✗An
n tuple” an OPTIONAL collection
n elements
ARelation is a subset of a cartesian
forexample, μ, {×,✗c.☐+}= g,,e, z,
NAME = {name / name is
a character
V with 1 . . 20 characters}.
{9,b,C,–. ,aa,ab,… .
– -. joe. – . . , . – . Mary. … .
dob / dob is a valid date}
{2001-Feb-1,2008-Dec-25,-. ..}
ID✗NAME✗DOB =
(a, ,b, ,c.),
(az,bz, c2),
A Possible Relation : o n ID ✗ N A M E ✗ D O B
{ ( 1 , j o e , 1 9 9 5 – M a r – 2 5) ,
(2 , jack , 2003-04-8 ) ,
(3, abby, 2006- Apr-22)}
ID Name Dob |$¥÷:÷fÉ
2003-04-8:
Representation of sets in computers
1,2, 3, – – . . 10}
{2,4, 6,8}
91,2, 3.4,5}
have a bit
equal to the size of the universe
U I 2 3 4 5 6 7 8 9 10
0I0I0I0I01
B lllI1OOOOO
AUB 1 I 1 I 1 I 0 I 0 1 Bitwise OR
AnB Ol0I0OOOOO
Bitwise AND
ADB10I0I10I01
Bitwise XOR
B- O O O O O l l l l 1
Bitwise NOT
1Intro There
§ Counting /Combinatorics a re lots in as w e
to count is o n e
steps in algorithm
motivating
example : How many
How many pins ?
are their have 4- digits .
– digits :
264 = 524 =
lowercase : upper / lower
More passwords ⇒
There is a havea2
” Brute force ” possibilities)
. can’t (attempting all
of things E.an-
better then The security of
7- 10 characters d.
uppercase , lowercase , jets 12 letters
} less obvious
how to count the
I 2 digits
size of this search space
restrictions
10,000 = 104 to possibilities
why you digit pin !!
size the .
why? To combat human nature : short passwords
are easy to remember
Sum and Product
pants-r-h-spatspa.rs
c a n w e a r o n e o r another . S o
h a v . 8 -16 = 14 options
Pantandkirts
Product Rule IB are
topickam aEA and ÷ .ie?I.::E ! ”
IA✗BI=/A/× /B/
m ore generally, A , , Az ,
/A.✗Azx. . -An/=/A, /✗ /Az/x – – – × /An/
char passwords : upper / lower /digit .
How many Pws do you have ?
A = { a ,b,c
1A 1 = 6 2
62✗62✗62✗62=62″=
14,776,336
” for each position I have 62
62 choices for position 1 AIN
Pick Representative from each d three
possibilities
Think about the problem in
English : multiplication /product
” OR” ⇒ addition /sum
this That ” Pick or
If A g B are disjoint finite then the # ways of picking a n
object from A of B is /At/B/
A n a l l mutually -.. then
1A, u Azu- . .UA,/=/A/+/Az/+. . ,
•j÷iÉ÷i÷÷÷
deck of S2 c a rd s
set of red cards = 2.6 set of face c a rd s = 1 2
How many ways can card that is red
I pick of a
NII 26+12=38 ✗(In double
face card? counting)
because Then
26+12-6=320
red face cards
of Inclusion /Exclusion says
LAUB/ =/A/ + /B)- /AnB/
T . h 4r e e . s e / – s –
elementfromAorB
Itstillworks whenthesetsare
“Pick an BorC
For larger sets , its a continuing series of inclusions É exclusions
/ =/ /AnBl- /An
ciistudentss
Three c o u rs e s :
Algebra , Biology , Chemistry
Subje4-#ÉABC_
Failed 12 5 8 2 6
How many students failed at least one course?
passed all three courses ?
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com