8
Discrete Mathematics Homework 1 Key Samet Öztoprak 2601140342 April 6, 2015 1) Show that each of these conditional statements is a tautology by using truth tables. a) (p q) → p p q p q (p q) → p T T T T T F F T F T F T F F F T b) p → (p q) p q p q p → (p q) T T F F T F T T F T T T F F T T c) ¬p → (p → q) p q ¬p p → q ¬p → (p → q) T T F T T T F F F T F T T T T F F T T T d) (p q) → (p → q) p q p q p → q (p q) → (p → q) T T T T T T F F F T F T F T T F F F T T

Discrete mathematic question answers

Embed Size (px)

Citation preview

Discrete Mathematics Homework 1 Key Samet Öztoprak

2601140342

April 6, 2015

1) Show that each of these conditional statements is a tautology by using truth tables.

a) (p ∧ q) → p

p q p ∧ q (p ∧ q) → p

T T T T

T F F T

F T F T

F F F T

b) p → (p ∨ q)

p q p ∨ q p → (p ∨ q)

T T F F

T F T T

F T T T

F F T T

c) ¬p → (p → q)

p q ¬p p → q ¬p → (p → q)

T T F T T

T F F F T

F T T T T

F F T T T

d) (p ∧ q) → (p → q)

p q p ∧ q p → q (p ∧ q) → (p → q)

T T T T T

T F F F T

F T F T T

F F F T T

e) ¬(p → q) → p

p q p → q ¬(p → q) ¬(p → q) → p

T T T F T

T F F T T

F T T F T

F F T F T

f ) ¬(p → q)→¬q

p q ¬q p → q ¬(p → q) ¬(p → q)→¬q

T T F T F T

T F T F T T

F T F T F T

F F T T F T

2) Determine whether each of these compound propositions is satisfiable.

a) (p ∨¬q) ∧ (¬p ∨ q) ∧ (¬p ∨¬q)

= (p ∧¬p) ∨ (p ∧ q) ∨ (¬q ∧¬p) ∨ (¬q ∧ q) ∧ (¬p ∨¬q)

(p ∧¬p) = F

(¬q ∧ q) = F

= (F ∨ (p ∧ q) ∨ (¬q ∧¬p) ∨ F) ∧ (¬p ∨¬q)

= (p ∧ q ∧ ¬p ) ∨ (¬q ∧ ¬p ∧ ¬p) ∨ (p ∧ q ∧ ¬q) ∨ (¬q ∧ ¬p ∧ ¬q)

(p ∧ q ∧ ¬p ) = F

(p ∧ q ∧ ¬q) = F

= F ∨ (¬q ∧ ¬p ∧ ¬p) ∨ F ∨ (¬q ∧ ¬p ∧ ¬q)

(¬p ∧ ¬p) = ¬p

= ¬q ∧ ¬p

b) (p → q) ∧ (p →¬q) ∧ (¬p → q) ∧ (¬p →¬q)

p → q = ¬p ∨ q

= (¬p ∨ q) ∧ (¬p ∨ ¬q) ∧ (¬(¬p) ∨ q) ∧ (¬(¬p) ∨ ¬q)

= (¬p ∨ q) ∧ (¬p ∨ ¬q) ∧ (p ∨ q) ∧ (p ∨ ¬q)

= ((¬p ∧ ¬p) ∨ (q ∧ ¬p) ∨ (¬p ∧ ¬q) ∨ (q ∧ ¬q)) ∧ ((p ∧ p) ∨ (q ∧ p) ∨ (p ∧ ¬q) ∨ (q ∧ ¬q))

= (¬p ∨ (q ∧ ¬p) ∨ (¬p ∧ ¬q)) ∧ (p ∨ (q ∧ p) ∨ (p ∧ ¬q) ) = (¬p ∧ p) ∨ (q ∧ ¬p ∧ p) ∨ (¬p ∧ ¬q ∧ p) ∨ (¬p ∧ q ∧ p) ∨ (q ∧ ¬p ∧ q ∧ p )

∨ (¬p ∧ ¬q ∧ q ∧ p ) ∨ (¬p ∧ p ∧ ¬q) ∨ (q ∧ ¬p ∧ p ∧ ¬q) ∨ (¬p ∧ ¬q ∧ p ∧ ¬q)

= False

c) (p ↔ q) ∧ (¬p ↔ q)

= (p ∧ q) ∨ (¬p ∧ ¬q) ∧ (¬ (p) ∧ q) ∨ (¬ (¬p) ∧ ¬q)

= ((p ∧ q) ∨ (¬p ∧ ¬q)) ∧ ((¬p ∧ q) ∨ ( p ∧ ¬ q))

= (p ∧ q ∧ ¬p ∧ q ) ∨ (p ∧ q ∧ p ∧ ¬ q) ∨ (p ∧ q ∧ ¬p ∧ q ) ∨ (p ∧ q ∧ p ∧ ¬ q)

= False

3) Translate each of these statements into logical expressions using predicates, quantifiers,

and logical connectives.

P(x) – x is perfect; F(x) – x is your friend

a) No one is perfect.

xP(x)

b) Not everyone is perfect.

P(x)

c) All your friends are perfect.

x[F(x) P(x)]

d) At least one of your friends is perfect.

x[F(x) P(x)]

e) Everyone is your friend and is perfect.

x[F(x) P(x)]

f ) Not everybody is your friend or someone is not perfect.

xF(x) xP(x) =[xF(x) xP(x)] = x[F(x) P(x)]

4) Give an arithmetic proof of ( ) + (

) = (

)

= ( ) + (

)

=

( ) +

( ) ( )

= (

( )

( ) ( ) )

= (

( ) ( )

( ) ( ) )

= (

( ) ( ) )

= (

( ) ( ) )

= ( )

( ) ( ) = (

)

5) Use a proof by contradiction to show that there is no rational number r for which r3 + r + 1

= 0. [Hint: Assume that r = a/b is a root, where a and b are integers and a/b is in lowest terms.

Obtain an equation involving integers by multiplying by b3. Then look at whether a and b are

each odd or even.]

it can suppose which is ‘b’ positive. therefore ‘a’ and ‘b’ are same sign,

then there is ‘a’ pair of positive numbers and ‘a’ pair of negative numbers for which the ratio ‘a’ / ‘b’ is

the same, so it is not point which pair we find; similarly,

if ‘a’ and ‘b’ have opposite signs, there is a fraction with positive numerator and negative denominator, and a fraction with negative numerator and positive denominator, for which the ratio ‘a’/’b’ is the

same.

r3 + r + 1 = 0

+

+ 1 = 0

a3 + ab

2 + b

3 = 0

a3 + b

3 = -a b

2

If a is also positive, then the left hand side is positive and the right hand side is negative; not possible.

If a is zero, then b must be zero; not possible since b is the denominator of our rational root. So a can only be negative.

Let's rearrange again:

a3 + ab

2 = b

3

a(a2 + b

2) = b

3 then (a

2 + b

2) = + always

a = b3

We know the right side is positive.

If ‘a’ is negative, then the left hand side is also negative. So, ‘a’ can not be negative.

Here is full proof.

a(a2 + b

2) = b

3 then (a

2 + b

2) = + always

a = b3

if | | | | and a = (-) b = (+) ( ) ( )

if | | | | and a = (+) b = (-) ( ) ( )

if | | | | and a = (-) b = (+) ( ) ( )

if | | | | and a = (+) b = (-) ( ) ( )

Since we have proven that ‘a’ cannot be positive, zero, or negative, then ‘a’ does not exist.

6) Let

A = [

]

a) A[2].

A[2] = AA = [

] [

]

= [

( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )

( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )

]

A[2] = [

]

b) A[3].

A[3] = A[2]A = [

] [

]

=[

( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( ) ( ) ∨ ( ) ∨ ( )

]

A[3]=[

]

c) A ∨ A[2] ∨ A[3]

A ∨ A[2] ∨ A[3] = [

] ∨ [

] ∨ [

]

A ∨ A[2] ∨ A[3] = [

( ∨ ∨ ) ( ∨ ∨ ) ( ∨ ∨ )( ∨ ∨ ) ( ∨ ∨ ) ( ∨ ∨ )( ∨ ∨ ) ( ∨ ∨ ) ( ∨ ∨ )

]

A ∨ A[2] ∨ A[3] = [

]

7) Let A be the set of English words that contain the letter x, and let B be the set of English

words that contain the letter q. Express each of these sets as a combination of A and B.

a) The set of English words that do not contain the letter x.

Solution : A

b) The set of English words that contain both an x and a q.

Solution : A ∩ B

c) The set of English words that contain an x but not a q.

Solution : A - B

d) The set of English words that do not contain either an x or a q.

Solution : A ∩ B

e) The set of English words that contain an x or a q, but not both.

Solution : (A ∪ B) - (A ∩ B)

8) Show that if A and B are sets, then A − (A − B) = A ∩ B.

Proof…

x ∈ A ∩ B. x ∈ A and x ∈ B.

Especially, x /∈ A - B (because x ∈ A \ B would imply x /∈ B).

Therefore x ∈ A - (A - B).

It shows us A∩B ⊆ A - (A - B).

Now let x ∈ A - (A - B). x ∈ A and x /∈ A - B.

This means that x /∈ A or x ∈ B (the negation of x ∈ A and x /∈ B).

Since we know x ∈ A, this implies x ∈ B,

Therefore x ∈ A∩B.

It shows us A - (A - B) ⊆ A∩B.

It shows us obviously A ∩ B = A - (A - B).

9) Describe an algorithm that takes as input a list of n integers and finds the location of the

last even integer in the list or returns 0 if there are no even integers in the list.

public class Main { public static int getLastEvenNumber(int[] array, int lenght) { if (array[lenght] % 2 == 0 ) return lenght+1; else if (lenght == 0) return 0; else return getLastEvenNumber(array, (lenght - 1)); } public static void main(String args[]) { int[] array = {1,3,5,7,9,1}; // first element in the 1st location. if there is no even return 0 System.out.println("index of last even number : " + getLastEvenNumber(array, array.length-1)); } }

10) A palindrome is a string that reads the same forward and backward. Describe an algorithm

for determining whether a string of n characters is a palindrome.

import java.util.Scanner; public class Main { public static boolean Ispalindrome(String word, int lenght) { if ((word.length() - lenght) >= (lenght - 1)) {} else if (word.charAt(word.length() - lenght) != word.charAt(lenght - 1)) return false; else Ispalindrome(word, lenght - 1); return true; } public static void main(String args[]) { Scanner sc = new Scanner(System.in); String word = sc.nextLine(); System.out.println((Ispalindrome(word, word.length()) ? "it is palidromic" : "it is not palidromic")); } }