Skip to content
Elvis Chidera

[WIP] Mathematics for Computer Science - Notes

notes8 min read

Chapter 1: What is a proof?

SymbolMeaning
Z+\mathbb{Z}^+Positive integers.
:=:=Equal by definition: It implies that the equality is based on a specific definition or set of rules rather than just numerical equivalence. It’s always ok simply to write == instead of ::=::= because something that is equal by definition is a form of equality.
\forallFor all.
NNon-negative integers.
\inElement of.

🙊 Propositions

A proposition is a statement that is either true or false. e.g. Fermat’s last theorem is a proposition that states “there are no positive integers xx, yy, and zz such that xn+yn=znx^n + y^n = z^n”. The proposition was shared by Fermat in 1630 and was only proven in 1994.

💡 You can't check a claim about an infinite set by checking a finite sample of its elements, no matter how large the sample.

A conjecture is a proposition that is believed to be true based on limited evidence but has not been proven. e.g. Goldbach’s conjecture states that “every even integer greater than 2 is the sum of two prime numbers”.

A predicate is a proposition whose truth depends on the value of one or more variables. e.g “n is a perfect square”.

Like propositions, predicates are named with letters, often with function notation. The output is either true or false depending on the input. This is in contrast to ordinary functions where the output is a numerical value. e.g. p(n) ::= n is a perfect square.

💡 Euler is pronounced “oiler”.

🧩 Logical operators

Logical operators or connectives are used to combine or modify logical propositions. These are the common logical connectives:

🙃 1. Negation (NOT)

Symbol: ¬\neg

Negation is a unary logical connective that takes a proposition PP to another proposition “not PP”, standing for “PP is not true”. It is interpreted intuitively as being true when PP is false, and false when PP is true.

PP¬P\neg P
TF
FT

🪢 2. Conjunction (AND)

Symbol: \land

A conjunction is a (binary) logical connective on two propositions that produces a value of true if and only if both propositions are true.

AABBABA \land B
FFF
FTF
TFF
TTT

💁 3. (Inclusive) Disjunction (OR)

Symbol: \lor

A disjunction is a (binary) logical connective on two propositions that produces a value of true if either one of the propositions is true.

AABBABA \lor B
FFF
FTT
TFT
TTT

👉 4. Implication (if…then)

Symbol:     \implies

A material implication or material conditional is a (binary) logical connective on two propositions that produces a value of true unless its first proposition (antecedent) is true and its second proposition (consequent) is false.

The only circumstance in which a conditional is false is if the consequent (QQ) does not follow when the antecedent (PP) is true. The material conditional is only concerned with the hypothetical relationship between PP and QQ, not their actual truth values.

✏️ I have always scratched my head as to why the conditional was defined to be true if the antecedent is false.

One explanation is that if the antecedent is false, then the relationship (implication) doesn't matter. But then this begs the question: Why not define it to be false?

One argument against that is that it would make the implication operator have the same truth table as the conjunction operator. But why is that a problem?

The argument that sits well with me so far is: The logical connectives must be truth-functional, i.e. its truth value is determined exclusively by the truth values of its arguments. Hence, we must define them to have a stable value. When PP is false, we have two viable options: return false or return true. We are using the latter option because of legacy reasons and because it “plays nicely” with the rest of the subject.

The material conditional (P    QP \implies Q) can be expressed in various ways:

  1. If PP, then QQ.
  2. PP implies QQ.
  3. PP only if QQ
  4. QQ if PP.
  5. QQ whenever PP.
PPQQP    QP \implies Q
FFT
FTT
TFF
TTT

👉👈 5. Equivalence (if and only if)

Symbol:     \iff

A material equivalence is a (binary) logical connective on two propositions that produces a value of true only if both both propositions are true or both are false.

"PP if and only if QQ" can be decomposed into "PP if QQ" and "PP only if QQ":

  • "PP if QQ": This is simply a different way of saying "If QQ then PP" (i.e. Q    PQ \implies P).
  • "PP only if QQ": which means PP can be true only if QQ is true, which is to say that when QQ is false, PP must also be false (i.e. P    QP \implies Q). Notice that it does not tell us anything about the truth value of PP if QQ is true.
    • If we know that PP is true, then we know QQ must also be true; however, if we know QQ is true, we do not necessarily know anything about the truth value of PP.
    • Consider the example: "The light bulb will go on only if the light switch works." If the light bulb goes on, then the switch must have worked, since failure of the switch would have meant darkness; however, if the light switch works, you don't necessarily know that the light bulb will go on, since there could be something wrong in the wiring or the bulb itself that keeps it from illuminating.

So, PP if and only if QQ is logically equivalent to (Q    P)(P    Q)(Q \implies P) \land (P \implies Q)

PPQQP    QP \implies QQ    PQ \implies PP    QP \iff Q
TTTTT
TFFTF
FTTFF
FFTTT

👫 Sufficiency and necessity

In implications relationships, a necessary condition is one (possibly one of multiple conditions) that must be present in order for another condition to occur, while a sufficient condition is one that produces the said condition.

In a conditional statement (P    QP \implies Q) that is true, the antecedent (PP) is a sufficient condition for the consequent (QQ) and the consequent is a necessary condition for the antecedent:

  • PP is a sufficient condition for QQ — because PP being true always implies that QQ is true.
  • QQ is a necessary condition for PP — because it is impossible to have PP without QQ (or put another way, the falsity of QQ ensures the falsity of PP).
Sufficiency and necessity venn diagram

Being in the purple region is sufficient for being in AA, but not necessary. Being in AA is necessary for being in the purple region, but not sufficient. Being in AA and being in BB is necessary and sufficient for being in the purple region.

e.g.

A number's being divisible by 4 is sufficient (but not necessary) for it to be even, but being divisible by 2 is both sufficient and necessary for it to be even.

🕵️ Inference rules

An inference is a set of premises together with a conclusion.

A rule of inference is a way or schema of drawing a conclusion from a set of premises, usually based only on the logical form of the premises.

Some common inference rules:

  1. Modus ponens:

    • ((P    Q)P)    Q((P \implies Q) \land P) \implies Q
    • PP implies QQ is true. PP is true. Therefore, QQ must also be true.
    • e.g.

      If today is Tuesday, then John will go to work. Today is Tuesday. Therefore, John will go to work.

  2. Modus tollens:

    • ((P    Q)¬Q)    ¬P((P \implies Q) \land \neg Q) \implies \neg P
    • PP implies QQ. QQ is false. Therefore, PP must also be false.
    • e.g.

      If the dog detects an intruder, the dog will bark. The dog did not bark. Therefore, no intruder was detected by the dog.

  3. Hypothetical syllogism:

    • ((P    Q)(Q    R))    (P    R)((P \implies Q) \land (Q \implies R)) \implies (P \implies R)
    • The antecedent of one premise must match the consequent of the other for the conditional to be valid.
    • e.g.

      If I do not wake up, then I cannot go to work. If I cannot go to work, then I will not get paid. Therefore, if I do not wake up, then I will not get paid.

  4. Disjunctive syllogism

    • ((PQ)¬P)    Q((P \lor Q) \land \neg P) \implies Q
    • If PP is true or QQ is true and PP is false, then QQ is true.
  5. Contraposition:

    • (P    Q)    (¬Q    ¬P)(P \implies Q) \iff (\neg Q \implies \neg P)
    • The statement ¬q    ¬p\neg q \implies \neg p is called the contraposition of p    qp \implies q.

✅ Validity & Soundness

An inference is valid if, assuming its premises are true, the conclusion must be true.

An inference is sound if it is valid and all of its premises are true (and as a consequence its conclusion is true as well).

e.g.

A sound inference

(premises)

All men are mortal.

Socrates is a man.

(conclusion)

Therefore, Socrates is mortal.

e.g.

A valid but unsound inference

All birds can fly.

Penguins are birds.

Therefore, penguins can fly.

✒️ Standard form

The standard form for inference rules is:

Premise 1Premise 2Conclusion\begin{gathered} \frac{ \begin{aligned} \text{Premise 1} \\ \text{Premise 2} \end{aligned} }{\text{Conclusion}} \end{gathered}

When the statements above the line (the premises or antecedents) are proved, then the statement below the line (the conclusion or consequent) is considered to also be proved.

❌ Fallacies

  1. Affirming the consequent:

    • e.g.

      If an animal is a dog, then it has four legs.

    My cat has four legs.

    Therefore, my cat is a dog.

  2. Denying the antecedent:

    • e.g.

      If you are a ski instructor, then you have a job.

      You are not a ski instructor.

      Therefore, you have no job.

  3. Begging the question:

🧑‍⚖️ Proofs

An axiom or postulate is a proposition that is taken to be true, to serve as a premise or starting point for further reasoning and arguments. For instance, Euclid begun with five assumptions (axioms) about geometry, which seemed undeniable based on direct experience, e.g. “There is a straight line segment between every pair of points”.

A proof is a sequence of logical deductions from axioms or previously proved statements (like theorems) that concludes with the proposition of interest.

Logical deductions or inference rules are used to prove new propositions using axioms or previously proved propositions.

The axiomatic method, invented by Euclid, is the standard procedure for establishing truth in mathematics using axioms and proofs.

📜 Proof terminologies

  1. Important true propositions are called theorems.
  2. A lemma is a preliminary proposition useful for proving later propositions.
  3. A corollary is a proposition that follows in just a few logical steps from a theorem.
  4. When an implication is translated by a hypothetical (or conditional) judgment, the antecedent is called the hypothesis (or the condition) and the consequent is called the thesis.

🧱 Types of proofs

1. 🎯 Direct proof

To prove p    qp \implies q directly, assume pp is true, then use axioms, definitions, rules of inference, and logical equivalences to prove qq is also true.

A useful technique in constructing direct proofs is working backwards:

  • Examine the conclusion qq and try to determine what statements would imply it.
  • Ask the same question about that statement and so on.
  • Combined with working forwards (what does pp imply?), you can work towards the middle.

e.g.

Proposition: “If a number is divisible by 66, then it is also divisible by 33

Proof:

  • Assume xx is divisible by 66 (💬 Assume pp).
  • x=k6x = k \cdot 6 (for some kk in Z\mathbb{Z}, by definition of division).
  • x=k(23)x = k \cdot (2 \cdot 3) (known fact about numbers).
  • x=(k2)3x = (k \cdot 2) \cdot 3 (associative property of multiplication).
  • x=m3x = m \cdot 3 (where m=k2m = k \cdot 2 is an integer).
  • xx is divisible by 33 \blacksquare (💬 Demonstrated that qq logically follows).

2. 🙃 Proof by contraposition (a type of indirect proof)

To prove p    qp \implies q by contraposition, assume qq is false, then use axioms, definitions, rules of inference, and logical equivalences to prove pp is also false. This is essentially a direct proof that ¬q    ¬p\neg q \implies \neg p.

The best approach in doing a proof by contrapositive is to restate the original problem in the form, If pp, then qq. The contrapositive is then, If not qq, then not pp.

e.g.

Proposition: “If xx is divisible by 66, then x is divisible by 33

Proof:

  • Assume xx is not divisible by 33 (💬 Assume ¬q\neg q).
  • xk3x \neq k \cdot 3 (kZ\forall k \in \mathbb{Z})
  • x2m3x \neq 2m \cdot 3 (mZ\forall m \in \mathbb{Z})
  • xm6x \neq m \cdot 6 (mZ\forall m \in \mathbb{Z})
  • xx is not divisible by 66 \blacksquare (💬 ¬p\neg p).

3. 🙅 Proof by contradiction (also a type of indirect proof)

This method works by assuming your implication is not true, then deriving a contradiction. Recall that if pp is false then p    qp \implies q is always true, thus the only way our implication can be false is if pp is true and qq is false.

In practice then, we assume our premise is true but our conclusion is false and use this to derive a contradiction: either a violation of a law or a previously established result. Having derived the contradiction you can then conclude that your assumption (that p    qp \implies q is false) was false and so the implication is true.

e.g.

Proposition: If x+x=xx + x = x then x=0x = 0

Proof:

  • Assume x+x=xx + x = x and x0x \neq 0.
  • Then 2x=x2x = x and since x0x \neq 0 we can divide both sides by xx to get 2=12 = 1 which is a contradiction.
  • Our assumption that the implication “If x+x=xx + x = x then x=0x = 0” is false is itself false, therefore the original implication is proven to be true. \blacksquare

4. 🙄 Trivial proof

A proof is trivial if the statement qq in the implication p    qp \implies q is true regardless of the truth value of pp.

e.g.

Prove A{}    AA \neq \{\} \implies A is a subset of ABA \cup B for any set BB.


5. 🤷 Vacuous proof

If the statement pp in the implication p    qp \implies q is false then the implication is always true.

e.g.

AA is a proper subset of A    AA \implies A is a proper subset of ABA \cap B for any set BB, where the containments here are strict.

🧱 8. Proof by cases

Some implications come in the form, p1p2...pn    qp_1 \lor p_2 \lor ... \lor p_n \implies q. Often these cases will be derived in the course of the proof. In this case you must prove that EACH of the separate implications, pi    qp_i \implies q is true.

👉👈 7. Proving an if and only if (iff)

🤝 Method 1: Prove each statement implies the other

The statement P    QP \iff Q is equivalent to the the two statements:

  • P    QP \implies Q and
  • Q    PQ \implies P

Hence, P    QP \iff Q can be proved by proving the two implications.

e.g.

Proposition: “P    QP \iff Q

Proof: First, we show P    QP \implies Q Use any of the types of proof above to prove this.

Finally, we show Q    PQ \implies P Use any of the types of proof above to prove this.

This proves the proposition because P    Q=(P    Q)(Q    P)P \iff Q = (P \implies Q) \land (Q \implies P) \blacksquare

⛓️ Method 2: Construct a chain of Iffs

To prove P    QP \iff Q is true, prove PP is equivalent to a second statement which is equivalent to a third statement and so forth until you reach QQ.

This method can lead to short & elegant proofs, but it requires more ingenuity than the first.

e.g.

Proposition: The standard deviation of a sequence of values x1x_1, … , xnx_n is zero iff all the values are equal to the mean (xˉ\bar{x}).

Proof: We construct a chain of “iff” implications, starting with the statement that the standard deviation is zero:

(x1xˉ)2+(x2xˉ)2+...+(xnxˉ)2n=0\sqrt{\frac{ (x_1 - \bar{x})^2 + (x_2 - \bar{x})^2 + ... + (x_n - \bar{x})^2}{n}} = 0

Now, since zero is the only number whose square root is zero, the equation above holds iff: (x1xˉ)2+(x2xˉ)2+...+(xnxˉ)2=0(x_1 - \bar{x})^2 + (x_2 - \bar{x})^2 + ... + (x_n - \bar{x})^2 = 0

Squares of real numbers are always non-negative, so every term on the left-hand side of the equation above is non-negative. This means the above equation holds iff: Every term on the left-hand side of the equation is zero.

But a term (xixˉ)2(x_i - \bar{x})^2 is zero iff xi=xˉx_i = \bar{x}, so the above statement is true iff: Every xix_i equals the mean (xˉ\bar{x}) \blacksquare

💪 Properties of a good proof

The same rigorous thinking needed for proofs is essential in the design of critical computer systems. When algorithms and protocols only "mostly work" due to reliance on hand-waving arguments, the results can range from problematic to catastrophic

  1. Concise — Not unnecessarily long.
    • When your proof need facts that are easily stated, but not readily proved, those facts can be pulled out as lemmas.
    • Also, repeated arguments can be captured in lemmas.
  2. Clear — A proof is an essay, not a calculation. Keep it unambiguous and include explanations.
  3. Linear & logical — Every statement logically follows from prior statements.
  4. Complete — Doesn't skip intermediary steps.
  5. Rigorous — Uses mathematical expressions.

Links

© 2024 by Elvis Chidera. All rights reserved.