Sunteți pe pagina 1din 39

ENGG1007 Foundations of Computer Science

Introduction
Hubert Chan Sep 17, 2012

Teaching Team
Hubert Chan Office: CB429 Email: hubert at cs I check my email frequently! Teaching Assistants Ning Li (HW-335A, lning at cs) Xiaowei Wu (CB-LG101, xwwu at cs) Dongxiao Yu (HW-335A, dxyu at cs) Please use ENGG1007: in subject.

Lecture Times
Monday 12:30-2:20pm LE8 (Class A) NO class on Oct 1 and Oct 29 Oct 4(Thursday) 12:30-1:20pm LE8 Monday 3:30-5:20pm LE8 (Class B) NO class on Oct 1 and Oct 29 Oct 4(Thursday) 3:30-4:20pm LE8

Tutorial (Compulsory)
Every Thursday afternoon (except Nov 1)
Class

A: 12:30-1:20pm LE8 Class B: 3:30-4:20pm LE8


There will be exercises during tutorials You need to attend at least 6 of 10 tutorials Only the highest 6 of the 10 tutorials will be counted (score 0 will be given to those tutorials you do not attend)

Consultation (Optional)
Instructor Office Hours One hour after each lecture, CYC 429 TA Office Hours Li Ning (One hour after each tutorial) HW-335A Xiaowei Wu: (One hour after each tutorial) CYC-LG101 Please inform the instructor (TA) after each lecture (tutorial) if you need to use his office hour. You can also send us emails to arrange appointments.

Timetable
Mon
12:30-2:20pm LE8 (Class A) 3:30-5:20pm LE8 (Class B)

Tue

Wed

Thu
12:30-1:20pm LE8 (Class A) 3:30-4:20pm LE8 (Class B)

Fri

Outside consultation hours: by appointments


6

Homepage and Newsgroup


Students are suggested to visit the course homepage and moodle regularly

Homepage:

http://i.cs.hku.hk/~engg1007/
We also use Moodle to publish announcements. You can use Moodle to communicate with the whole class. Please send us email for a prompt response.
7

Textbook
Discrete Mathematics and Its Applications (6th Edition) Kenneth H. Rosen, McGraw-Hill International Editions.

Exercise questions from the book could appear in Homeworks and Exam!

Assessment
3-hour examination + continuous assessment Examination: 50% Continuous assessment: 50%
3

homeworks: 25%

10

tutorials/exercise: 25%

Only the highest 6 of the 10 tutorials will be counted

Homeworks
Assignment Box (B1 for class A, B2 for class B): CYC Building 3/F Late Policy: 1 day late: 50% penalty 2 days late: no marks will be given Assignments should be submitted before 7 pm on the due date. Scheduled assignments (deadlines): Oct 15, Nov 12, Dec 10
10

Plagiarism
Plagiarism is the action of using or copying someone else's idea or work and pretending that you thought of it or created it. First Attempt: Students who admit committing plagiarism for the first time shall be warned in writing and receive a zero mark for the component concerned. For those who do not confess, the case would be referred to the Programme Director for consideration. Subsequent Attempt: If students commit plagiarism more than once during the course of studies, the case shall be referred to the Programme Director for consideration. The Programme Director will investigate the case and consider referring it to the University Disciplinary Committee, which may impose any of the following penalties: a published reprimand, suspension of study for a period of time, fine, or expulsion from the University.

But discussing with classmates is encouraged!


11

Outcome Based Learning: Objectives


[O1 Abstract Concepts] Understand abstract mathematical concepts which are fundamental to computer science, e.g., logic, sets, functions, basic probability, graph theory. [O2 Proof Techniques] Be able to perform abstract thinking and present logical argument using techniques such as mathematical induction, proof by contradiction. [O3 Basic Analysis Techniques] Be able to apply formal reasoning to analyze and enumerate the possible outcomes of a computational problem e.g. model and compute the number of operations using recursion, counting and combinatorics.
12

Topics
Logic Sets and relations Counting Probability Graphs
13

Logic (Chapter 1)
([O1, O2]; chapters 1.1, 1.2) Propositional Logic Basic Definitions Logical operators Predicate Logic Predicates Quantified expressions

14

A Puzzle
In the middle of the journey to a village, you need to select whether to go East or West at a branch. One is the path to hell and the other is to heaven, but you cannot tell which is which. Each villager always tells the truth or always lies and will only give a Yes or a No response to a question. You are only allowed to ask a villager one question to determine the way to heaven. What to ask? If you can ask two questions, the problem is trivial. Question 1: 4 > 5? Question 2: Is East the way to heaven? Yet you are allowed to ask only one question!
15

Propositions Definition
Def: A proposition is a statement that is either true (T) or false (F), but not both. Which of the followings are propositions? 1 + 1 = 7. Do you feel hungry? Hong Kong is the largest city of China. 1 + 3. x + 2. Come here quickly!

16

Compound Proposition
A proposition (compound proposition) can be formed by combining several propositions using logical operators. Logical operators: (negation), (and), (or), (exclusive or), (implication), (biconditional) Example: Mr. Wong is stupid and his wife is lazy. p: Mr. Wong is stupid q: his wife is lazy. p q: where stands for connective and A compound proposition also has a truth value (T or F) depending on the truth values of its constituting propositions and the operator(s).
17

Logical operators
And (Conjunction) - Let p and q be two propositions, (p q) is defined to be true if both p and q are true, and false otherwise. Example: (Today is Friday) (2 is a factor of 15) ---- False Or (Disjunction) - Let p and q be two propositions, (p q) is defined to be true if either p or q or both are true, and false otherwise. Exclusive-or - Let p and q be two propositions, then (p q) is defined to be true if either p or q, but not both, is true, and false otherwise. Not (Negation) - Let p be a proposition, p is defined to be true if p is false. Otherwise p is false.
18

Truth Table
Truth table can be used to display the truth values of propositions and is useful in determining the truth values of complicated proposition. Truth Tables for (negation), (and), (or), (exclusive-or)

p
All possible cases. How many?

q T F T F

pq pq pq T F F F T T T F F T T F
19

T T F F

p T F

p F T

p and q are two propositions

Logical operators: (negation), (and), (or), (exclusive or), (implication), (biconditional) The implication pq is the proposition that is false when p is true and q is false, and true otherwise.

p T T F F

q T F T F

pq T F T T

pq is often read as p implies q or if p, then q


Intuitively, the statement has no problem if the hypothesis p is not true. Example: Let p denote John is a CS major, q denote Mary is Johns girl friend. r denote pq
T T F
20

Whats the truth value of r if (a) John is NOT a CS major, Mary is Johns girl friend (b) John is NOT a CS major, Mary is NOT Johns girl friend (c) John is a CS major, Mary is NOT Johns girl friend

Remarks: 1
The mathematical concept of an implication vs daily usage of English

If today is Friday, then 2+3 = 5

daily usage

Assumes a relationship between the hypothesis & conclusion But the implication is true according to the definition. Also, the meaning of the if-then statement is different when used in a program

if (x > 3) then y = x;
If the value of x is greater than 3, then execute the statement y = x
21

The bicondition pq is the proposition that is true both p and q have the same truth values and is false otherwise.

p T T F F

q T F T F

p q T F F T

pq is often read as p if and only if q or p is necessary and sufficient for q Remark: pq is true when both pq and qp are true.

Example: (X is an even number) (X+1 is an odd number)

22

Exercise: Let p and q be the propositions. p: It is below freezing q: It is snowing Write the following propositions using p and q and logical connectives (operators). (a) It is below freezing but not snowing. (b) It is either below freezing or it is snowing, but it is not snowing if it is below freezing. (c) It is either below freezing or snowing, but not both.

p q (p q) (p q)

pq

23

Logically equivalence
We say that the two propositions p and q are logically equivalent if pq is always true. We denote this relationship by pq (or p q). That is, either both are true or both are false. Claim: (p q) (p q) Again, we can prove it using truth table!

24

Some important equivalences


Obvious Rules pTp pFp Commutative pqqp pqqp Q: Is addition commutative? (p + q = q + p ?) Q: Is subtraction commutative? (p q = q p?) pTT pFF ppp ppp (p) p

Associative (p q) r p (q r) (p q) r p (q r)

Q: Is multiplication associative? Q: Is division associative?

Q: (p q) r p (q r) ?? To show that it is not correct: Let p = F, q = F, r = T


25

More.
(Distributive Law) p (q r) (p q) (p r) p (q r) (p q) (p r) (Negation Law) p p T p p F (De Morgans Law) (p q) p q (p q) p q (Implication Law) (p q) (p q)

26

Question to be asked: If I were to ask you whether East is the way to heaven, would you answer yes? If the correct answer is East: The honest answer is Yes. For the dishonest villager,
If

he is asked whether East is the way to heaven? (Q1) What would be his answer? No So, if we ask him If I were to ask you whether East is the way to heaven, would you answer yes? Since his own answer to Q1 is No, so he lies, and would answer Yes to this question.

Similarly for the incorrect answer, both will answer No.

27

ENGG1007 Foundations of Computer Science

Predicates and Quantifiers


([O1, O2]; chapters 1.3, 1.4)

28

Predicates
Is x > 3 a proposition? No, unless the value of x is fixed. Let P(x) denote the statement x > 3 where P(x) is called a propositional function. P(x) has a truth value once the value of x is fixed. E.g. P(5) is true; P(1) is false. P actually refers to the property is greater than 3 and is called the predicate. Note that x is a variable (the subject). A propositional function can have more than one variable (multivalue predicates). E.g. Let Q(x, y) denote x + y > 10. Then, Q(4, 5) is false; Q(5, 6) is true.
29

Universe of Discourse
The collection of values that a variable x may take is called the universe of discourse or domain. Example: x is rich, x can refer to people in HK, the world, movies stars, IT people, For the statement x is prime, the universe of discourse of x is the set of all positive integers.

30

Quantification (Quantifiers)
Two ways to convert a propositional function, say P(x), into a proposition. Assign value(s) to variable(s). Quantify variable(s): P(x) is true for all possible values of x (Universal Quantification) These exists at least one value of x such that P(x) is true (Existential Quantification)
Example: Let P(x) denote the statement x has a million dollars.

P(x) has no truth value and is not a proposition. P(John) is a proposition. x P(x) is a proposition. for all possible values of x (universe of discourse), P(x) is true e.g. x P(x) is false where domain is people in this room.
31

Universal and Existential Quantification


Suppose the universe of discourse (domain) of P(x) is {x1, x2, x3 } The universal quantification x P(x) P(x1) P(x2) P(x3) P(x) is true for all possible values of x The existential quantification x P(x) P(x1) P(x2) P(x3) P(x) is true for at least one value of x

32

Example: Let P(x) denote the statement x is married. P(x) has no truth value and is not a proposition. P(Peter) is a proposition. x P(x) is a proposition. there exist an x from the possible values, P(x) is true e.g. x P(x) is true where u.o.d. is the postgrad students in our dept. Examples (the universe of discourse is the set of integers): What is the truth value of the following? x (x2 = x) x (x2 = x) x [y (x+y = x-y)] x [y (x+y = x-y)]

33

Example
To express: Every student in the FCS class is smart. All students in the FCS class are smart. etc. Lets make the universe of discourse be the set of all students (including those not in FCS class). Let P(x) be the statement x is smart. Let Q(x) be the statement x is in the FCS class. Can you write down the expression? x (Q(x) P(x)) which means all students are in FCS class and smart Answer: x (Q(x) P(x))
34

Example
To express: Some students in the FCS class are smart. At least one student in the FCS class is smart. Not all students in the FCS class are stupid Let P(x) be the statement x is smart. Let Q(x) be the statement x is in the FCS class. Lets make the universe of discourse be the set of all students. Can you write down the expression? x (Q(x) P(x)) which cannot guarantee at least one student in FCS class is smart (e.g. there can be no students in FCS class and there is one student, say Peter, who is not in FCS class, the statement is still true!). Answer: x (Q(x) P(x))
35

Quantifier Equivalences
Suppose the universe of discourse is {x1, x2, x3,}. x P(x) P(x1) P(x2) P(x3) x P(x) P(x1) P(x2) P(x3) By the De Morgans Law, (p q) p q (p q) p q we can prove that x P(x) x P(x) x P(x) x P(x)
36

Compared the previous example with this one. Let P(x) denote x likes to drive A(x) denote x has an expensive car Are x (P(x) A(x)) and (x P(x)) (x A(x)) equivalent?

No, here is the counterexample. Let the universe of discourse has only Peter and May. P(Peter) is true, but A(Peter) is false; P(May) is false, but A(May) is true; So, x (P(x) A(x)) is true but (x P(x)) (x A(x)) is false

37

Ordering of quantifiers If x y M(x, y) is true, can we say that y x M(x, y) is also true? If y x M(x, y) is true, can we say that x y M(x, y) is also true? Hint: Let M(x, y) denote the statement x + y = 10

Note: Transposing different kinds of quantifiers may have different meanings However, two quantifiers of the same kind can be transposed without changing the meaning of the expression.
x y x y

Q(x, y) Q(x, y)

y x Q(x, y) y x Q(x, y)

38

Some Conventions
The universe of discourse may be restricted within the quantification. x > 0 P(x) x (x > 0 P(x)) [ For all x that are greater than zero, P(x) holds ] x > 0 P(x) x (x > 0 P(x)) [ There is an x greater than zero such that P(x) holds. ] The universe of discourse is restricted from a set of integers to a set of positive integers
Try some exercises on Sec. 1.3, 1.4
39

S-ar putea să vă placă și