Discrete Mathematics (H) Midterm Review Note

24 minute read

Published:

1 Logic

1 Logic

1.1 Propositional Logic

1.1.1 Propositions

A proposition is a declarative sentence that is either true or false, but not both. For example, “SUSTech is in Shenzhen” is a proposition, while “No parking on campus” is not a proposition.

1.1.2 Logical Connectives

There are six logical connectives in propositional logic, which are negation(¬), conjunction(), disjunction(), exclusive or(), implication(), and biconditional().

For implication pq, we call p the hypothesis and q the conclusion.

The converse of pq is qp. The inverse of pq is ¬p¬q. The contrapositive of pq is ¬q¬p.

1.1.3 Tautologies and Contradictions

A tautology is a proposition that is always true, regardless of the truth values of its individual components. A contradiction is a proposition that is always false. A contingency is a proposition that is neither a tautology nor a contradiction.

1.1.4 Logical Equivalences

Two propositions are logically equivalent if they have the same truth values for all possible combinations of truth values of their component propositions.

The propositions p and q are logically equivalent if and only if pq is a tautology, denoted by pq or pq.

1.1.5 Important Logical Equivalences

  • Identity laws

    pTp
    pFp
  • Domination laws

    pTT
    pFF
  • Idempotent laws

    ppp
    ppp
  • Double negation laws

    ¬(¬p)p
  • Commutative laws

    pqqp
    pqqp
  • Associative laws

    (pq)rp(qr)
    (pq)rp(qr)
  • Distributive laws

    p(qr)(pq)(pr)
    p(qr)(pq)(pr)
  • De Morgan’s laws

    ¬(pq)¬p¬q
    ¬(pq)¬p¬q
  • Absorption laws

    p(pq)p
    p(pq)p
  • Negation laws

    p¬pT
    p¬pF
  • Useful law

    pq¬pq

1.2 Predicate Logic

1.2.1 Predicates and Quantifiers

A constant models a specific object. A variable represents objects of specific type. A predicate represents properties or relations among objects.

However, a predicate is not a proposition, because it is not a declarative sentence. It becomes a proposition when the variable is assigned a value. Additionally, the universal quantification and existential quantification of a predicate is a proposition. For example, Prime(x) is not a proposition, while Prime(3) and xPrime(x) are propositions.

The universe(domain) D of a predicate is the set of all objects that can be substituted for the variables in a predicate. The truth set of a predicate P(x) is the set of objects in the universe that can be substituted for x in P(x) to make the resulting proposition true.

The truth values of xP(x) and xP(x) depend on both the universe and the predicate P(x).

1.2.2 Precedence of Quantifiers

The quantifiers and have higher precedence than all the logical operators. For example, xP(x)Q(x) means (xP(x))Q(x), not x(P(x)Q(x)).

1.2.3 Translation with Quantifiers

Universal quantification

Sentence: All SUSTech students are smart.

Universe: all students

Translation: x(At(x,SUSTech)Smart(x))

Typical error: x(At(x,SUSTech)Smart(x)), which means all students are at SUSTech and smart.

Existential quantification

Sentence: Some SUSTech students are smart.

Universe: all students

Translation: x(At(x,SUSTech)Smart(x))

Typical error: x(At(x,SUSTech)Smart(x)), this is true if there is anyone who is not at SUSTech.

1.2.4 Nested Quantifiers

The order of nested quantifiers is important. For example, let L(x,y) denotes “x loves y”, then xyL(x,y) means “Everyone loves someone”, while yxL(x,y) means “There is someone whom everyone loves”.

However, the order of nested quantifiers does not matter if quantifiers are of the same type.

1.2.5 Negating Quantifiers

  • ¬xP(x)x¬P(x)

  • ¬xP(x)x¬P(x)

  • ¬xyP(x,y)xy¬P(x,y)

2 Mathematical Proofs

2.1 Theorems and Proofs

2.1.1 Definitions

An axiom or postulate is a statement or proposition that is regarded as being established, accepted, or self-evidently true. A theorem is a statement or proposition that can be proved to be true. A lemma is a statement that can be proved to be true, and is used in proving a theorem.

In formal proofs, steps follow logically from the set of premises, axioms, lemmas, and other previously proved theorems.

2.1.2 Rules of inference

  • Modus Ponens: ((pq)p)q

  • Modus Tollens: ((pq)¬q)¬p

  • Hypothetical Syllogism: ((pq)(qr))(pr)

  • Disjunctive Syllogism: ((pq)¬p)q

  • Addition: p(pq)

  • Simplification: (pq)p

  • Conjunction: ((p)(q))(pq)

  • Resolution: ((pq)(¬pr))(qr)

  • Universal instantiation: xP(x)P(c)

  • Universal generalization: P(c) for an arbitrary cxP(x)

  • Existential instantiation: xP(x)P(c) for some element c

  • Existential generalization: P(c)xP(x)

2.1.3 Methods of Proof

To proof pq:

  • Direct proof: Show that if p is true then q follows.

  • Proof by contrapositive: Show that ¬q¬p.

  • Proof by contradiction: Show that p¬q contradicts the assumptions.

  • Proof by cases: Give proofs for all possible cases.

  • Proof of equivalence pq: Prove pq and qp.

3 Sets and Functions

3.1 Sets

3.1.1 Definitions

A set is an unordered collection of objects, called elements or members of the set. We can represent a set by listing its elements between braces, or defining a property that its elements satisfy.

3.1.2 Important Sets

  • is the set of natural numbers.

  • is the set of integers. + is the set of positive integers.

  • is the set of rational numbers.

  • is the set of real numbers.

  • is the set of complex numbers.

  • 𝕌 is the set of all objects under consideration.

  • is the empty set. Note: {}

  • P(S) is the power set of S, which is the set of all subsets of S.

  • Disjoint sets A and B are sets that have no elements in common, i.e., AB=.

3.1.3 Set Operations

  • Union: AB={x|xA or xB}

  • Intersection: AB={x|xA and xB}

  • Difference: A-B={x|xA and xB}

  • Complement: A¯={x|xU and xA}

  • Cartesian product: A×B={(a,b)|aA and bB}

3.1.4 Cardinality

The cardinality of a set S, denoted by |S|, is the number of distinct elements in the set. The sets A and B have the same cardinality if there is a one-to-one correspondence between them. If there is a one-to-one function from A to B, the cardinality of A is less than or equal to the cardinality of B, denoted by |A||B|.

A set that is either finite or has the same cardinality as the set of positive integers + is called countable. A set that is not countable is called uncountable.

Here are some examples of countable and uncountable sets:

  • Countable Sets: ,,,+, the set of finite strings S over a finite alphabet A

  • Uncountable Sets: , P()

The subset of a countable set is still countable.

To prove a set is countable, we can use Schröder-Bernstein theorem. If there are one-to-one functions f:AB and g:BA, then there is a one-to-one correspondence between A and B, and |A|=|B|.

To prove a set is uncountable, we can use Cantor’s diagonalization method. Assume that S is countable, then we can list all elements of S in a table. Then we can construct a new element that is not in the table, which contradicts the assumption that S is countable.

For power set, we have the following formula:

|P(S)|=2|S|

For union and intersection, we have the following formulas:

|AB|=|A|+|B|-|AB|

For Cartesian product, we have the following formula:

|A×B|=|A|×|B|

Note: ||=0 and |{}|=1

3.1.5 Computable vs. Uncomputable

We say a function is computable if there is an algorithm that can compute the function’s value for any input in a finite amount of time.

There are functions that are not computable. This is true because the set of computer programs is countable, while the set of functions from to the set {0,1,2,,9} is uncountable. (Cantor’s diagonalization method)

3.1.6 Cantor’s Theorem

For any set S, |S|<|P(S)|.

This is obviously true for finite sets, because |P(S)|=2|S|. (Note that ||=0,|P()|=1)

For infinite sets, we can prove this by contradiction. Assume that |S|=|P(S)|, then there is a one-to-one correspondence between S and P(S). Let f be a function from S to P(S), then we can construct a set T={sS|xf(s)}. Since f is a one-to-one correspondence, there must be an element s0S such that f(s0)=T. However, s0T implies s0T, which is a contradiction.

To build a one-to-one function from P(S) to S is trivial, because we can just map each subset of S to its smallest element.

Hence, we know that |S||P(S)| and |S||P(S)|. Therefore, |S|<|P(S)|.

3.1.7 Set Identities

  • Identity laws

    A=A
    AU=A
  • Domination laws

    AU=U
    A=
  • Idempotent laws

    AA=A
    AA=A
  • Complementation laws

    A¯¯=A
  • Commutative laws

    AB=BA
    AB=BA
  • Associative laws

    (AB)C=A(BC)
    (AB)C=A(BC)
  • Distributive laws

    A(BC)=(AB)(AC)
    A(BC)=(AB)(AC)
  • De Morgan’s laws

    AB¯=A¯B¯
    AB¯=A¯B¯
  • Absorption laws

    A(AB)=A
    A(AB)=A
  • Complement laws

    AA¯=U
    AA¯=

3.2 Tuples

An ordered n-tuple is a sequence of n elements, where n is a positive integer.

3.3 Functions

3.3.1 Definitions

Let A and B be sets. A function f from A to B, denoted by f:AB, is an assignment of exactly one element of B to each element of A.

We represent a function by a formula or explicitly state the assignments between elements of A and B. For example, let A={1,2,3} and B={a,b,c,d}, then f:AB can be represented by 1a,2b,3c.

Let f:AB be a function. We say that A is the domain of f and B is the codomain of f. If f(a)=b, b is the image of a under f, and a is a preimage of b. The range of f is the set of all images of elements of A, denoted by f(A).

3.3.2 Injective, Surjective, and Bijective Functions

A function f:AB is injective (one-to-one) if and only if f(a1)=f(a2) implies a1=a2 for all a1,a2A. A function f:AB is surjective (onto) if and only if f(A)=B. A function f:AB is bijective (one-to-one correspond) if and only if f is both injective and surjective.

The inverse of a function, denoted by f-1(x), is only defined for bijective functions.

3.3.3 Sequences

A sequence is a function from a subset of integers (typically {0,1,2,} or {1,2,3,}) to a set S. We use the notation an to denote the image of n under the function, and we call an the nth term of the sequence.

4 Complexity of Algorithms

4.1 Big-O Notation

We say that f(n)=O(g(n)) (reads as “f(n) is big-O of g(n)”) if there are positive constants c and n0 such that |f(n)||cg(n)| for all nn0.

Important big-O estimation:

  • n!=O(nn)

  • logn!=O(nlogn) (Actually we can prove logn!<nlogn<2logn!)

  • logan=O(n) for any a2

  • nk=O(an) for any k and a>1

Similarly, we can define big-Ω and big-Θ.

4.2 Algorithms

An algorithm is a finite set of precise instructions for performing a computation or for solving a problem. A computational problem is a specification of the desired input-output relationship. An instance of a computational problem is a specific input. A correct algorithm halts with the correct output for every instance of the problem, and we can say that the algorithm solves the problem.

4.2.1 Time and Space Complexity

The time complexity of an algorithm is the number of machine operations it performs on an instance. The space complexity of an algorithm is the number of cells of memory it uses on an instance.

4.2.2 Input Size

The input size is the number of bits needed to represent the input. For an integer n, the input size actually is log2(n+1) (or just log2n). Therefore, an algorithm that runs in Θ(n) seems to be linear and efficient, but it is actually exponential (Θ(n)=Θ(2size(n))).

We say two positive functions f(n) and g(n) are of the same type if and only If

c1g(na1)b1f(n)c2g(na2)b2

for all large n and some positive constants c1,c2,a1,a2,b1,b2.

Therefore, all polynomial functions are of the same type, and all exponential functions are of the same type. But polynomial functions are not of the same type as exponential functions.

4.2.3 Decision Problems and Optimization Problems

A decision problem is a question that has two possible answers: yes or no. An optimization problem is a question that requires an answer that is an optimal configuration.

If L is a decision problem and x is the input, we often write xL to mean that the answer to the decision problem is yes, and xL to mean that the answer is no.

An optimization problem usually has a corresponding decision problem.

4.2.4 Complexity Classes

We divide the set of all decision problems into three complexity classes.

A problem is solvable (tractable) in polynomial time if there is an algorithm that solves the problem and the number of steps required by the algorithm on any instance of size n is O(nk) for some constant k.

The class P is the set of all decision problems that are solvable in polynomial time. The class NP is the set of all decision problems for which there exists a certificate for each yes-input that can be verified in polynomial time.

4.2.5 NP Completeness

Reduction is a relationship between two problems. We say Q can be reduced to Q if every instance of Q can be transformed into an instance of Q such that the answer to the transformed instance is yes if and only if the answer to the original instance is yes.

A polynomial-time reduction from Q to Q is a reduction that can be performed in polynomial time, denoted by QpQ. Intuitively, this means Q is no harder than Q.

A problem Q is NP-complete if and only if

  • QNP

  • Every problem LNP, LpQ

Therefore, if we can find a polynomial-time algorithm for an NP-complete problem, then we can solve all NP problems in polynomial time.

5 Number Theory

5.1 Divisibility and Modular Arithmetic

5.1.1 Divisibility

Let a,b,c be integers. Then the following holds:

  • If a|b and a|c, then a|(b+c) and a|(b-c).

  • If a|b, then a|bc.

  • If a|b and b|c, then a|c.

  • Corollary: If a,b,c are integers, where a0, such that a|b and a|c, then a|(mb+nc) for any integers m and n.

5.1.2 Modular Arithmetic

Let a,b,n be integers, where n>0. We say that a is congruent to b modulo n, denoted by ab(modn), if and only if n|(a-b). This is called congruence and n is called the modulus.

The following properties hold:

  • If ab(modn) and cd(modn), then a+cb+d(modn).

  • If ab(modn) and cd(modn), then acbd(modn).

  • Corollary: (a+b)modm=((amodm)+(bmodm))modm, and (ab)modm=((amodm)(bmodm))modm.

5.2 Prime

An integer p>1 is prime if and only if its only positive divisors are 1 and p. An integer n>1 is composite if and only if it is not prime.

The fundamental theorem of arithmetic states that every integer greater than 1 is either prime or can be written as a unique product of prime numbers.

GCD of two integers a and b, denoted by gcd(a,b), is the largest integer that divides both a and b. If we factorize a and b into prime numbers, then gcd(a,b)=p1min(e1,f1)p2min(e2,f2)pkmin(ek,fk), where ei and fi are the exponents of pi in the factorization of a and b. Two integers are relatively prime if and only if their GCD is 1.

Similarly, we can define LCM of two integers a and b, denoted by lcm(a,b), is the smallest positive integer that is divisible by both a and b.

5.3 Eculidean Algorithm

The Eculidean algorithm is an efficient method for computing the GCD of two integers. It can solve the problem in O(logn) time, where n is the smaller of the two integers.

The central idea is that if a=bq+r, then gcd(a,b)=gcd(b,r). Here is the proof: If d is a common divisor of a and b, we can write da and db. By the corollary, we know that d(a-bq), which implies dr. Therefore, d is a common divisor of b and r.

For example, to compute gcd(287,91):

287mod91=14
91mod14=7
14mod7=0

Therefore, gcd(287,91)=7.

5.4 Bezout’s Theorem

Let a and b be integers, not both zero. Then there exist integers x and y such that gcd(a,b)=ax+by.

We can use the extended Eculidean algorithm to find x and y.

For example, since gcd(503,286)=1, we can find x and y such that 503x+286y=1, with the following steps:

Firstly, we use the Eculidean algorithm to find the GCD of 503 and 286:

503=1286+217
286=1217+69
217=369+10
69=610+9
10=19+1
9=91+0

Then, we can find x and y:

1=10-19
=10-1(69-610)=710-169
=7(217-369)-169=7217-269
=7217-22(286-1217)=2921722286
=29(503-1286)-22286=2950351286

Therefore, x=29 and y=-51.

The corollaries of Bezout’s theorem are:

  • If 1=gcd(a,b) and a|bc, then a|c.

  • If p is a prime and p|a1a2an, then p|ai for some i.

  • If acbc(modn) and gcd(c,n)=1, then ab(modn).

The proof of the first corollary is as follows: Since gcd(a,b)=1, we can find x and y such that ax+by=1. Then c=cax+cby. Since a|bc, we know that a|cby. Therefore, a|(cax+cby)=c.

5.5 Linear Congruence

A linear congruence is an equation of the form axb(modn), where a,b,n are integers and n>0.

5.5.1 Modular Inverse

Let a and n be integers, where n>0. If there exists an integer a¯ such that aa¯1(modn), then a¯ is called the modular inverse of a modulo n.

If a and n are relatively prime, then a has a modular inverse modulo n. Furthermore, the modular inverse of a modulo n is unique modulo n.

We can use the extended Eculidean algorithm to find the modular inverse of a modulo n.

5.5.2 Chinese Remainder Theorem

Let n1,n2,,nk be positive integers that are pairwise relatively prime, and let a1,a2,,ak be any integers. Then the system of linear congruences:

xa1(modn1)
xa2(modn2)
xak(modnk)

has a solution, and any two solutions are congruent modulo n1n2nk.

Let n=n1n2nk. Then the solution is x=a1y1nn1+a2y2nn2++akyknnk, where yi is the modular inverse of nni modulo ni.

For example, to solve the system of linear congruences:

x2(mod3)
x3(mod5)
x2(mod7)

We can find y1=2, y2=1, and y3=1. Therefore, x=2352+3211+2151=233 is a solution.

5.6 Fermat’s Little Theorem

Let p be a prime and a be an integer such that a0(modp). Then ap-11(modp).

5.7 Euler’s Theorem

Euler’s function ϕ(n) is the number of positive integers less than or equal to n that are relatively prime to n. The function has the following properties:

  • If p is prime, then ϕ(p)=p-1.

  • If p is prime and k1, then ϕ(pk)=pk-pk-1.

  • If m and n are relatively prime, then ϕ(mn)=ϕ(m)ϕ(n).

Euler’s theorem states that if n is a positive integer and a is an integer such that a and n are relatively prime, then aϕ(n)1(modn).

It is worth noting that ϕ(n) might not be the smallest positive integer k such that ak1(modn).

5.8 Primitive Roots

A primitive root modulo a prime p is an integer g such that every nonzero integer modulo p is congruent to a power of g modulo p.

6 Groups, Rings, and Fields

6.1 Groups

A group is a set G together with a binary operation * on G such that the following axioms hold:

  • Closure: For all a,bG, a*bG.

  • Associativity: For all a,b,cG, (a*b)*c=a*(b*c).

  • Identity: There exists a unique element 1eG such that for all aG, a*1e=a.

  • Inverse: For each aG, there exists an element a-1G such that a*a-1=1e.

6.1.1 Permutation Groups

A permutation group is a group whose elements are permutations of a given set S and whose operation is composition of permutations in S. Let sn=<1,2,,n> denotes a sequence of n elements, and Pn denotes the set of all permutations of sn. Then for any two elements π and ρ, πρ is also a permutation of sn.

For example, s3=<1,2,3>, and P3={<1,2,3>,<1,3,2>,<2,1,3>,<2,3,1>,<3,1,2>,<3,2,1>}. If π=<3,2,1> and ρ=<1,3,2>, then πρ=<2,1,3>. The operation is πρ[i]=ρ[π[i]].

Therefore, (Pn,) is a group.

6.1.2 Abeilian Groups

A group G is abeilian if and only if for all a,bG, a*b=b*a.

6.2 Rings

If (R,+) is an abeilian group, we define a second binary operation * on R such that the following axioms hold:

  • Closure: For all a,bR, a*bR.

  • Associativity: For all a,b,cR, (a*b)*c=a*(b*c).

  • Distributivity: For all a,b,cR, a*(b+c)=a*b+a*c and (a+b)*c=a*c+b*c.

6.2.1 Commutative Ring

A ring R is commutative if and only if for all a,bR, a*b=b*a.

6.2.2 Integral Domain

A commutative ring R is an integral domain if the following axiom holds:

  • Identity: There exists a unique element 1mR such that for all aR, a*1m=1m*a=a.

  • Nonzero product: For all a,bR, if a*b=0, then a=0 or b=0.

6.3 Fields

A commutative ring F is a field if the following axiom holds:

  • Inverse: For each aF, there exists an element a-1F such that a*a-1=a-1*a=1m.

6.4 Other Facts

  • Zm, the set of integers modulo m, is a commutative ring.

  • (GL(n),) is a group but not an abeilian group. (The set of all invertible n×n matrices)

  • (𝕄n×n,+,) is a ring but not a commutative ring.

  • (Zm,+m,m) is a commutative ring but not an integral domain.

  • (,+,) is an integral domain but not a field.

7 Cryptography

7.1 Public Key Cryptography

7.1.1 RSA Cryptosystem

The RSA public key cryptosystem works as follows:

  1. 1.

    Choose two large primes p and q.

  2. 2.

    Compute n=pq and ϕ(n)=(p-1)(q-1).

  3. 3.

    Choose e such that 1<e<ϕ(n) and gcd(e,ϕ(n))=1.

  4. 4.

    Compute d such that ed1(modϕ(n)).

  5. 5.

    Publish the public key (n,e) and keep the private key d secret.

To encrypt a message m, compute cme(modn). To decrypt a ciphertext c, compute mcd(modn).

The correctness of the algorithm is as follows:

cd(me)d(modn)
med(modn)
mkϕ(n)+1(modn)
m(mϕ(n))k(modn)
m1k(modn)
m(modn)

To leave a RSA signature, compute smd(modn). To verify a RSA signature, compute mse(modn).(d and e are interchangeable)

7.1.2 El Gamal Cryptosystem

The El Gamal public key cryptosystem works as follows:

  1. 1.

    Choose a large prime p and a primitive root g modulo p.

  2. 2.

    Choose x such that 1<x<p-2.

  3. 3.

    Compute ygx(modp).

  4. 4.

    Publish the public key (p,g,y) and keep the private key x secret.

To encrypt a message m, choose k such that 1<k<p-1 and gcd(k,p-1)=1, then compute c1gk(modp) and c2myk(modp). To decrypt a ciphertext (c1,c2), compute mc2(c1x)-1(modp).

The correctness of the algorithm is as follows:

c2(c1x)-1myk(gkx)-1(modp)
mgkxg-kx(modp)
m(modp)

7.2 Diffie-Hellman Key Exchange

The Diffie-Hellman key exchange works as follows:

  1. 1.

    Choose a large prime p and a primitive root g modulo p.

  2. 2.

    Alice chooses x such that 1<x<p-2 and sends ygx(modp) to Bob.

  3. 3.

    Bob chooses z such that 1<z<p-2 and sends wgz(modp) to Alice.

  4. 4.

    Alice computes wx(gz)xgzx(modp).

  5. 5.

    Bob computes yz(gx)zgxz(modp).

  6. 6.

    Now Alice and Bob share the secret key gxz(modp).

8 Mathematical Induction

8.1 Proof by Smallest Counterexample

To prove a statement P(n) for all nn0, we can use proof by smallest counterexample. We assume that P(n) is false for some n>0. Then there must be a smallest integer m such that P(m) is false. Since P(n0) is true, m>n0. Then we use the fact that P(m) the for all 0m<m is true to show that P(m) is true, which is a contradiction.

8.2 Direct Proof

8.2.1 Weak Principle of Mathematical Induction

If the statement P(b) is true, and the statement P(n-1)P(n) is true for all integers n>b, then the statement P(n) is true for all integers nb.

We call P(b) the basis step (inductive hypothesis) and P(n-1)P(n) the inductive step (inductive conclusion).

8.2.2 Strong Principle of Mathematical Induction

If the statement P(b) is true, and the statement P(b)P(b+1)P(n-1)P(n) is true for all integers n>b, then the statement P(n) is true for all integers nb.

We can see that the weak form is a special case of the strong form, and the strong form can be derived from the weak form.