Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Courses›Reasoning›Mathematical Reasoning and Proofs

Advanced Logical Systems

Mathematical Reasoning and Proofs

Mathematical reasoning and proofs form the foundation of logical thinking, enabling you to verify truths beyond empirical observation. They matter because they provide certainty in complex systems, from algorithms to formal verification, where intuition alone fails. You reach for them when designing robust systems, debugging edge cases, or constructing arguments that must hold under all conditions.

Understanding Propositions and Logical Connectives

A proposition is a statement that is either true or false, but not both. Logical connectives—such as AND (∧), OR (∨), NOT (¬), IMPLIES (→), and IF AND ONLY IF (↔)—allow us to combine propositions into more complex expressions. For example, the statement 'If it rains, then the ground is wet' can be written as 'rain → wet'. Understanding these connectives is crucial because they form the building blocks of all logical arguments. By mastering them, you can dissect complex statements into simpler parts, analyze their truth conditions, and construct valid proofs. The key insight is that the truth of a compound statement depends entirely on the truth of its components and the rules of the connectives. This section introduces a truth table, a tool that systematically enumerates all possible truth values of a proposition, ensuring you can verify its validity in every scenario.

# Truth table for the proposition: (A AND B) OR (NOT A)
# Demonstrates how logical connectives interact under all possible truth values of A and B.

def truth_table():
    print("A | B | A ∧ B | ¬A | (A ∧ B) ∨ ¬A")
    print("------------------------------")
    for A in [True, False]:
        for B in [True, False]:
            and_result = A and B
            not_A = not A
            final_result = and_result or not_A
            print(f"{int(A)} | {int(B)} |   {int(and_result)}   |  {int(not_A)} |        {int(final_result)}")

truth_table()
# Output:
# A | B | A ∧ B | ¬A | (A ∧ B) ∨ ¬A
# ------------------------------
# 1 | 1 |   1   |  0 |        1
# 1 | 0 |   0   |  0 |        0
# 0 | 1 |   0   |  1 |        1
# 0 | 0 |   0   |  1 |        1

Direct Proofs: Constructing Logical Arguments

A direct proof is the simplest form of mathematical proof, where you start with known facts (axioms or previously proven theorems) and use logical deductions to arrive at the statement you want to prove. For example, to prove 'If n is even, then n² is even', you begin by assuming n is even, which means n = 2k for some integer k. Squaring both sides gives n² = 4k² = 2(2k²), which is clearly even. The power of direct proofs lies in their transparency: each step follows inevitably from the previous one, leaving no room for doubt. This method is particularly useful for proving implications (P → Q), where you assume P is true and show Q must also be true. The challenge is often in identifying the right starting point and the sequence of logical steps, which requires practice and familiarity with algebraic manipulations or definitions relevant to the problem.

# Direct proof: Prove that the sum of two even numbers is even.
# Assumes basic knowledge of even numbers (n = 2k for some integer k).

def prove_sum_even(a, b):
    # Assume a and b are even
    k1 = a // 2  # Integer division to find k for a
    k2 = b // 2  # Integer division to find k for b
    
    # Express a and b as 2k
    assert a == 2 * k1, "a is not even"
    assert b == 2 * k2, "b is not even"
    
    # Sum of a and b
    sum_ab = a + b
    sum_ab_expressed = 2 * k1 + 2 * k2
    
    # Factor out 2 to show the sum is even
    sum_ab_factored = 2 * (k1 + k2)
    
    print(f"Given a = {a} and b = {b}, their sum is {sum_ab}.")
    print(f"Expressed as 2*{k1} + 2*{k2} = 2*({k1 + k2}) = {sum_ab_factored}.")
    print(f"Since {sum_ab} = 2*({k1 + k2}), it is even.")

prove_sum_even(4, 6)
# Output:
# Given a = 4 and b = 6, their sum is 10.
# Expressed as 2*2 + 2*3 = 2*(5) = 20.
# Since 10 = 2*(5), it is even.

Proof by Contradiction: Assuming the Opposite

Proof by contradiction is a powerful technique where you assume the opposite of what you want to prove and show that this assumption leads to a contradiction. If the assumption leads to an impossible situation, the original statement must be true. For example, to prove '√2 is irrational', you assume the opposite—that √2 is rational—and express it as a fraction a/b in lowest terms. Squaring both sides gives 2 = a²/b², implying a² is even, so a must be even. Writing a = 2k leads to 2 = 4k²/b², so b² must also be even, meaning b is even. This contradicts the assumption that a/b is in lowest terms, proving √2 is irrational. The strength of this method is that it allows you to use the assumption itself as a tool to uncover hidden contradictions. It is particularly useful for statements that are difficult to approach directly, such as those involving irrationality or infinity.

# Proof by contradiction: Prove that √2 is irrational.
# Assumes basic knowledge of even numbers and fractions in lowest terms.

def prove_irrational():
    # Assume √2 is rational, so √2 = a/b where a and b are coprime integers
    # (i.e., the fraction is in lowest terms).
    
    # Square both sides: 2 = a²/b² → a² = 2b²
    # This implies a² is even, so a must be even (since the square of an odd number is odd).
    
    # Let a = 2k for some integer k.
    # Substitute: (2k)² = 2b² → 4k² = 2b² → b² = 2k²
    # This implies b² is even, so b must be even.
    
    # But if both a and b are even, they share a common factor of 2,
    # contradicting the assumption that a/b is in lowest terms.
    
    print("Assume √2 is rational, so √2 = a/b where a and b are coprime.")
    print("Then a² = 2b², so a² is even, implying a is even (a = 2k).")
    print("Substituting: (2k)² = 2b² → b² = 2k², so b² is even, implying b is even.")
    print("This contradicts the assumption that a/b is in lowest terms.")
    print("Therefore, √2 must be irrational.")

prove_irrational()
# Output:
# Assume √2 is rational, so √2 = a/b where a and b are coprime.
# Then a² = 2b², so a² is even, implying a is even (a = 2k).
# Substituting: (2k)² = 2b² → b² = 2k², so b² is even, implying b is even.
# This contradicts the assumption that a/b is in lowest terms.
# Therefore, √2 must be irrational.

Inductive Proofs: Proving Statements for All Natural Numbers

Mathematical induction is a technique for proving statements that hold for all natural numbers. It consists of two steps: the base case, where you verify the statement for the smallest number (usually 0 or 1), and the inductive step, where you assume the statement holds for some arbitrary number k (the inductive hypothesis) and prove it holds for k+1. For example, to prove that the sum of the first n natural numbers is n(n+1)/2, you start by showing it holds for n=1 (base case). Then, assume it holds for n=k, and show that the sum for n=k+1 is (k+1)(k+2)/2. The power of induction lies in its ability to extend a finite verification into an infinite proof. It is particularly useful for recursive definitions, sequences, or any property that builds incrementally. The key insight is that the inductive step bridges the gap between one case and the next, allowing the truth to propagate indefinitely.

# Proof by induction: Prove that the sum of the first n natural numbers is n(n+1)/2.
# Base case: n=1. Inductive step: Assume true for n=k, prove for n=k+1.

def prove_sum_formula(n):
    # Base case: n = 1
    base_case = 1 * (1 + 1) // 2
    assert base_case == 1, "Base case fails"
    print(f"Base case (n=1): Sum = {base_case}, which matches 1.")
    
    # Inductive step: Assume true for n=k, prove for n=k+1
    for k in range(1, n):
        sum_k = k * (k + 1) // 2  # Inductive hypothesis
        sum_k_plus_1 = sum_k + (k + 1)  # Sum for n=k+1
        expected = (k + 1) * (k + 2) // 2
        
        print(f"For n={k+1}: Sum = {sum_k} + {k+1} = {sum_k_plus_1}")
        print(f"Expected: ({k+1})*({k+2})//2 = {expected}")
        assert sum_k_plus_1 == expected, f"Inductive step fails for k={k}"
    
    print(f"Inductive proof holds for n={n}.")

prove_sum_formula(5)
# Output:
# Base case (n=1): Sum = 1, which matches 1.
# For n=2: Sum = 1 + 2 = 3
# Expected: 2*3//2 = 3
# For n=3: Sum = 3 + 3 = 6
# Expected: 3*4//2 = 6
# For n=4: Sum = 6 + 4 = 10
# Expected: 4*5//2 = 10
# For n=5: Sum = 10 + 5 = 15
# Expected: 5*6//2 = 15
# Inductive proof holds for n=5.

Formal Systems and Axiomatic Reasoning

A formal system is a framework for reasoning that consists of axioms (self-evident truths), rules of inference (logical steps to derive new statements), and theorems (statements proven using the axioms and rules). For example, Euclidean geometry is a formal system where axioms like 'two points determine a line' serve as the foundation for proving theorems like the Pythagorean theorem. Axiomatic reasoning is essential because it provides a rigorous, unambiguous way to derive truths without relying on intuition or empirical evidence. In computer science, formal systems underpin everything from programming language semantics to automated theorem provers. The challenge lies in selecting a minimal set of axioms that are both consistent (no contradictions) and complete (can prove all true statements in the system). Gödel's incompleteness theorems show that no sufficiently powerful formal system can be both, highlighting the limits of axiomatic reasoning. This section introduces how to construct and work within such systems, emphasizing precision and logical structure.

# A minimal formal system: Propositional logic with axioms and inference rules.
# Axioms:
# 1. A → (B → A)
# 2. (A → (B → C)) → ((A → B) → (A → C))
# 3. (¬B → ¬A) → (A → B)
# Inference rule: Modus Ponens (if A and A→B, then B).

def formal_system_demo():
    # Example: Prove A → A using the axioms and Modus Ponens.
    
    # Step 1: Use Axiom 1 with A and B = A → A
    # A → ((A → A) → A)
    step1 = "A → ((A → A) → A)"
    print(f"Step 1: {step1} (Axiom 1)")
    
    # Step 2: Use Axiom 2 with A, B = A → A, C = A
    # (A → ((A → A) → A)) → ((A → (A → A)) → (A → A))
    step2 = "(A → ((A → A) → A)) → ((A → (A → A)) → (A → A))"
    print(f"Step 2: {step2} (Axiom 2)")
    
    # Step 3: Apply Modus Ponens to Step 1 and Step 2
    # (A → (A → A)) → (A → A)
    step3 = "(A → (A → A)) → (A → A)"
    print(f"Step 3: {step3} (Modus Ponens on Step 1 and Step 2)")
    
    # Step 4: Use Axiom 1 with A and B = A
    # A → (A → A)
    step4 = "A → (A → A)"
    print(f"Step 4: {step4} (Axiom 1)")
    
    # Step 5: Apply Modus Ponens to Step 4 and Step 3
    # A → A
    step5 = "A → A"
    print(f"Step 5: {step5} (Modus Ponens on Step 4 and Step 3)")
    
    print("Proved: A → A")

formal_system_demo()
# Output:
# Step 1: A → ((A → A) → A) (Axiom 1)
# Step 2: (A → ((A → A) → A)) → ((A → (A → A)) → (A → A)) (Axiom 2)
# Step 3: (A → (A → A)) → (A → A) (Modus Ponens on Step 1 and Step 2)
# Step 4: A → (A → A) (Axiom 1)
# Step 5: A → A (Modus Ponens on Step 4 and Step 3)
# Proved: A → A

Key points

  • Propositions are statements that are either true or false, and logical connectives combine them into complex expressions whose truth depends on their components.
  • Direct proofs start with known facts and use logical deductions to arrive at the statement to be proven, making them transparent and easy to verify.
  • Proof by contradiction assumes the opposite of what you want to prove and shows that this leads to a contradiction, thereby proving the original statement.
  • Mathematical induction proves statements for all natural numbers by verifying a base case and showing that if the statement holds for one case, it holds for the next.
  • Formal systems consist of axioms, rules of inference, and theorems, providing a rigorous framework for deriving truths without relying on intuition.
  • Axiomatic reasoning is essential in computer science for designing systems with unambiguous semantics, such as programming languages or automated theorem provers.
  • Gödel's incompleteness theorems demonstrate that no sufficiently powerful formal system can be both consistent and complete, revealing fundamental limits in axiomatic reasoning.
  • Mastering these proof techniques enables you to construct robust arguments, debug edge cases, and reason about systems where intuition alone is insufficient.

Common mistakes

  • Mistake: Assuming a statement is true because it holds for a few examples. Why it's wrong: Proofs require general reasoning, not just verification of specific cases. Fix: Always provide a general argument or counterexample.
  • Mistake: Confusing necessary and sufficient conditions. Why it's wrong: A necessary condition must hold for a statement to be true, but it doesn't guarantee the statement. A sufficient condition guarantees the statement but isn't always required. Fix: Clearly distinguish between the two in proofs.
  • Mistake: Using circular reasoning (assuming what you're trying to prove). Why it's wrong: This creates a logical loop with no actual proof. Fix: Ensure each step logically follows from previous steps or axioms, not the conclusion.
  • Mistake: Misapplying induction by skipping the inductive step or assuming the base case covers all scenarios. Why it's wrong: Induction requires both a base case and a step showing that if it holds for *n*, it holds for *n+1*. Fix: Explicitly verify both parts of the induction.
  • Mistake: Overlooking implicit assumptions in proofs (e.g., assuming a set is non-empty without justification). Why it's wrong: Hidden assumptions can invalidate a proof. Fix: State all assumptions explicitly and justify them.

Interview questions

What is a direct proof, and how would you use it to show that the sum of two even integers is always even?

A direct proof is a logical argument where we start with given premises and use definitions, axioms, and previously established theorems to reach a conclusion. To prove that the sum of two even integers is always even, we begin by defining even integers. An integer is even if it can be written as 2k, where k is an integer. Let’s take two even integers, say a = 2m and b = 2n, where m and n are integers. Their sum is a + b = 2m + 2n = 2(m + n). Since m + n is also an integer, the sum a + b is of the form 2k, which means it is even. This completes the direct proof by showing the conclusion follows necessarily from the definitions.

Explain what a proof by contradiction is, and demonstrate it by proving that √2 is irrational.

A proof by contradiction assumes the opposite of what we want to prove and shows that this assumption leads to a logical inconsistency, thereby confirming the original statement must be true. To prove that √2 is irrational, we assume the opposite: that √2 is rational. This means it can be expressed as a fraction a/b, where a and b are integers with no common factors (the fraction is in simplest form), and b ≠ 0. Squaring both sides gives 2 = a²/b², or a² = 2b². This implies a² is even, so a must also be even (since the square of an odd number is odd). Let a = 2k for some integer k. Substituting back, we get (2k)² = 2b², so 4k² = 2b², and thus b² = 2k². This means b² is even, so b must also be even. But if both a and b are even, they share a common factor of 2, contradicting our assumption that a/b is in simplest form. Therefore, √2 cannot be rational, and must be irrational.

What is mathematical induction, and how would you use it to prove that the sum of the first n positive integers is n(n + 1)/2?

Mathematical induction is a proof technique used to establish that a statement holds for all natural numbers. It consists of two main steps: the base case and the inductive step. For the base case, we verify the statement for the smallest value, usually n = 1. Here, the sum of the first 1 integer is 1, and the formula gives 1(1 + 1)/2 = 1, so it holds. For the inductive step, we assume the statement is true for some arbitrary positive integer k, i.e., the sum of the first k integers is k(k + 1)/2. We then prove it for k + 1: the sum of the first k + 1 integers is the sum of the first k integers plus (k + 1). By the inductive hypothesis, this is k(k + 1)/2 + (k + 1) = (k + 1)(k/2 + 1) = (k + 1)(k + 2)/2, which matches the formula for n = k + 1. Since both steps are satisfied, the formula holds for all positive integers n by induction.

Compare proof by contrapositive with proof by contradiction. When would you choose one over the other, and why?

Proof by contrapositive and proof by contradiction are both indirect proof techniques, but they differ in structure and use cases. The contrapositive of a statement 'If P, then Q' is 'If not Q, then not P,' and proving the contrapositive is logically equivalent to proving the original statement. In contrast, proof by contradiction assumes the entire statement is false (i.e., P and not Q) and derives a contradiction. Contrapositive is often cleaner and more direct when the negation of Q leads naturally to the negation of P, as it avoids introducing additional assumptions. For example, to prove 'If n² is even, then n is even,' the contrapositive 'If n is not even, then n² is not even' is straightforward to prove. Proof by contradiction is more flexible and can be used when the contrapositive is not obvious or when the statement involves complex negations. However, it can be less elegant because it requires assuming the opposite of the entire statement, which may introduce unnecessary complexity. Choose contrapositive when the negation of the conclusion directly implies the negation of the premise, and contradiction when the relationship is less clear or when the statement is existential or universal.

Prove that there are infinitely many prime numbers using a method that does not rely on Euclid’s classic proof. Provide a detailed explanation of your approach.

One alternative to Euclid’s proof is to use the fact that every integer greater than 1 has a unique prime factorization. Assume, for contradiction, that there are only finitely many primes, say p₁, p₂, ..., pₙ. Consider the number N = p₁p₂...pₙ + 1. By our assumption, N must be divisible by at least one of the primes pᵢ, since every integer greater than 1 has a prime factor. However, N leaves a remainder of 1 when divided by any pᵢ, so it is not divisible by any of them. This means N must either be a prime itself or have a prime factor not in our original list, contradicting the assumption that p₁, p₂, ..., pₙ are all the primes. Therefore, there must be infinitely many primes. This proof is similar to Euclid’s but emphasizes the uniqueness of prime factorization, which is a fundamental result in number theory. The key insight is that N cannot be factored into any of the assumed finite primes, forcing the existence of a new prime.

Explain how you would construct a proof for the statement: 'For all real numbers x, if x² - 5x + 6 < 0, then 2 < x < 3.' Include the reasoning behind each step and why the approach is valid.

To prove this statement, we start by analyzing the inequality x² - 5x + 6 < 0. First, we factor the quadratic expression: x² - 5x + 6 = (x - 2)(x - 3). The inequality becomes (x - 2)(x - 3) < 0. To solve this, we determine where the product of the two factors is negative. A product of two numbers is negative when one factor is positive and the other is negative. We identify the critical points where the expression equals zero, which are x = 2 and x = 3. These points divide the real number line into three intervals: x < 2, 2 < x < 3, and x > 3. We test each interval: for x < 2 (e.g., x = 1), both factors are negative, so the product is positive; for 2 < x < 3 (e.g., x = 2.5), (x - 2) is positive and (x - 3) is negative, so the product is negative; for x > 3 (e.g., x = 4), both factors are positive, so the product is positive. Thus, the inequality holds only when 2 < x < 3. This proves the original statement because we’ve shown that the hypothesis (x² - 5x + 6 < 0) is true if and only if the conclusion (2 < x < 3) is true. The approach is valid because it relies on the properties of quadratic inequalities and the intermediate value theorem, ensuring that the solution set is correctly identified.

All Reasoning interview questions →

Check yourself

1. Which of the following is a valid way to disprove the statement 'All prime numbers are odd'?

  • A.Show that 2 is a prime number and even.
  • B.List the first 100 odd primes and note no even numbers appear.
  • C.Assume the statement is true and derive a contradiction.
  • D.Prove that all even numbers greater than 2 are composite.
Show answer

A. Show that 2 is a prime number and even.
The correct answer is to show that 2 is a prime number and even, which directly contradicts the statement. The other options are incorrect because: (1) Listing examples doesn't disprove a universal claim. (2) Assuming the statement is true and deriving a contradiction is a proof by contradiction, but the statement is already false, so this isn't the most direct method. (3) Proving that all even numbers greater than 2 are composite doesn't address the existence of 2, the only even prime.

2. Consider the statement: 'If *n* is divisible by 4, then *n* is divisible by 2.' Which of the following correctly describes the converse of this statement?

  • A.If *n* is divisible by 2, then *n* is divisible by 4.
  • B.If *n* is not divisible by 4, then *n* is not divisible by 2.
  • C.If *n* is not divisible by 2, then *n* is not divisible by 4.
  • D.The statement has no converse because it is always true.
Show answer

A. If *n* is divisible by 2, then *n* is divisible by 4.
The converse of 'If P, then Q' is 'If Q, then P.' Here, P is '*n* is divisible by 4' and Q is '*n* is divisible by 2,' so the converse is 'If *n* is divisible by 2, then *n* is divisible by 4.' The other options are incorrect because: (1) The second option is the inverse, not the converse. (2) The third option is the contrapositive of the converse, not the converse itself. (3) Every statement has a converse, regardless of its truth value.

3. In a proof by contradiction, what is the role of the assumption you make at the beginning?

  • A.To temporarily assume the statement you want to prove is false, so you can derive a contradiction.
  • B.To assume the statement is true and show it leads to a known true statement.
  • C.To list all possible cases and eliminate the ones that don't hold.
  • D.To provide an example that satisfies the statement's conditions.
Show answer

A. To temporarily assume the statement you want to prove is false, so you can derive a contradiction.
In a proof by contradiction, you assume the negation of the statement you want to prove (i.e., assume it is false) and then derive a contradiction. This shows the original assumption must be false, so the statement is true. The other options are incorrect because: (1) Assuming the statement is true and showing it leads to a true statement is not a proof by contradiction. (2) Listing cases is a proof by exhaustion, not contradiction. (3) Providing an example is a proof by example, not contradiction.

4. Which of the following is an example of a necessary but not sufficient condition for a number to be prime?

  • A.The number is greater than 1.
  • B.The number is not divisible by any integer other than 1 and itself.
  • C.The number is odd.
  • D.The number has exactly two distinct positive divisors.
Show answer

C. The number is odd.
A necessary condition for a number to be prime is that it must satisfy the condition, but the condition alone doesn't guarantee the number is prime. Here, 'the number is odd' is necessary for all primes except 2, but it is not sufficient (e.g., 9 is odd but not prime). The other options are incorrect because: (1) 'Greater than 1' is necessary but also part of the definition of a prime, so it is both necessary and sufficient when combined with other conditions. (2) 'Not divisible by any integer other than 1 and itself' is the definition of a prime, so it is both necessary and sufficient. (4) 'Exactly two distinct positive divisors' is also the definition of a prime, so it is both necessary and sufficient.

5. Suppose you are proving the statement 'For all integers *n*, if *n* is even, then *n²* is even.' Which of the following is a valid first step in a direct proof?

  • A.Assume *n* is odd and show *n²* is odd.
  • B.Assume *n* is even and write *n* = 2k for some integer *k*.
  • C.Assume *n²* is even and show *n* is even.
  • D.List all even integers and square them to check the pattern.
Show answer

B. Assume *n* is even and write *n* = 2k for some integer *k*.
In a direct proof, you assume the hypothesis (here, '*n* is even') is true and then show the conclusion ('*n²* is even') follows. Writing *n* = 2k is a standard way to express an even integer. The other options are incorrect because: (1) Assuming *n* is odd is irrelevant to the statement. (2) Assuming *n²* is even and showing *n* is even is the converse of the statement. (3) Listing examples is not a proof, as it doesn't cover all cases.

Take the full Reasoning quiz →

← PreviousFormal Proof TechniquesNext →Game Theory and Strategic Reasoning

Reasoning

36 lessons, free to read.

All lessons →

Track your progress

Sign in to mark lessons done, score quizzes and keep notes.

Open in the app