Skip to content

Instantly share code, notes, and snippets.

@simonespa
Last active February 1, 2026 12:00
Show Gist options
  • Select an option

  • Save simonespa/dfc054eafdc5493d8cb04f79cb215c7b to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/dfc054eafdc5493d8cb04f79cb215c7b to your computer and use it in GitHub Desktop.
Computer Science and AI fundamentas

Soundness and Completeness

In formal logic and related fields, a system (such as a set of rules for proof) is considered sound if it cannot prove anything false, and complete if it can prove everything that is true.

Soundness

  • Definition: A proof system is sound if any formula that can be derived (proven) within the system is logically valid (true under all interpretations).
  • Guarantee: It ensures that all conclusions reached through the system's rules are correct. You can trust any statement that the system proves.
  • Informal: "You can't prove anything that's wrong".
  • Example: An argument like "All elephants are pink. Nelly is an elephant. Therefore, Nelly is pink" is valid in its form, but it is not sound because its first premise is false. A sound argument must have both a valid structure and true premises.

Completeness

  • Definition: A proof system is complete if every logically valid formula can be proven within the system using its rules and axioms.
  • Guarantee: It ensures the system is powerful enough to capture all truths within its scope. It does not miss any valid statements.
  • Informal: "You can prove anything that's right".
  • Example: Propositional logic is an example of a system that is both sound and complete. This means that a statement is provable if and only if it is a tautology (always true).

The Ideal

A system that is both sound and complete is highly desirable because it proves all and only the true statements, establishing a perfect link between the mechanics of proof (syntax) and the concept of truth (semantics). Would you like to know more about how these concepts apply in specific fields like computer science or mathematics? AI responses may include mistakes. Learn more

Kurt Gödel’s Incompleteness Theorems

Published in 1931, the Kurt Gödel’s Incompleteness Theorems are two foundational results in mathematical logic demonstrating that any consistent, sufficiently complex formal axiomatic system (like arithmetic) is incomplete. This means such systems contain true statements that cannot be proven within the system, proving there are inherent limits to mathematical provability and formal reasoning.

Key Aspects of Gödel's Incompleteness Theorems:

  • The First Incompleteness Theorem: Any consistent, formal system $$F$$ that includes basic arithmetic contains statements that can neither be proved nor disproved within $$F$$. Gödel constructed a statement that essentially says, "This statement cannot be proven". If the system could prove it, the system would be false; if it cannot prove it, the statement is true.
  • The Second Incompleteness Theorem: A consistent, formal system (F) capable of basic arithmetic cannot prove its own consistency. It cannot prove that it is free from contradictions within itself.
  • Impact on Mathematics: The theorems shattered the Hilbert program, which sought to formalize all of mathematics and prove its consistency. It demonstrated that truth is a larger concept than proof, meaning not all true mathematical statements can be proven.
  • Significance Beyond Math: The results apply to any formalised system, including computer programming languages and artificial intelligence, suggesting inherent limitations in what computers can verify or prove.

This video explains the paradox at the heart of Gödel's incompleteness theorem: https://www.youtube.com/watch?v=I4pQbo5MQOs

Essentially, Gödel proved that for any consistent, "reasonable" mathematical system, there will always be truths that the system cannot prove, and the system cannot prove that it is not broken (consistent).

Watch this video for a detailed, illustrated explanation of how Gödel's proof works: https://www.youtube.com/watch?v=u3GYrEOoKGk

The First Incompleteness Theorem

This theorem states that in any consistent formal system that is powerful enough to include basic arithmetic (like Peano Arithmetic), there will always be statements that are true but unprovable within that system.

  • The "Gödel Sentence": Gödel constructed a specific mathematical statement (G) that essentially says, "This statement is not provable in this system".
  • The Logic: If the system could prove G, it would be proving a false statement (since G says it's unprovable), meaning the system would be inconsistent. If the system cannot prove G, then G is true, but the system is incomplete.
  • A "Hydra" Effect: Simply adding G as a new axiom doesn't solve the problem; a new, different unprovable statement can always be constructed for the expanded system.

The Second Incompleteness Theorem

This theorem is a direct consequence of the first. it states that a consistent system cannot prove its own consistency.

  • Mathematical Humility: To prove that a system like arithmetic has no contradictions, you must use a stronger system with more axioms (which itself cannot prove its own consistency).
  • Hilbert's Dream: These results effectively ended David Hilbert’s quest to find a complete and consistent set of axioms for all of mathematics.

Key Concepts and Impact

  • Arithmetization (Gödel Numbering): Gödel’s genius was in creating a way to encode logical statements as numbers, allowing mathematics to "talk about itself".
  • Truth vs. Provability: The theorems highlighted that truth is a larger concept than provability.
  • Philosophy and AI: The theorems have sparked deep debates in the philosophy of mind, with some arguing they prove human minds can never be fully replicated by computers (Turing machines).

Hilbert's program

Initiated by David Hilbert in the 1920s, the Hilbert's program was a foundational project to secure mathematics against paradoxes by formalizing it into an axiomatic system and proving its consistency using only "finitary" methods. It aimed to prove that all mathematics is complete, consistent, and decidable.

Key aspects and outcomes include:

  • Goal: To establish a rigorous foundation for mathematics, particularly by justifying the use of infinite sets and abstract concepts through a "finitistic" (concrete) approach.
  • Components: The program focused on formalizing mathematical theories, proving they are free from contradiction (consistency), showing that all true statements can be derived (completeness), and ensuring the conservation of "real" results from "ideal" (abstract) methods.
  • Impact of Gödel: Kurt Gödel's incompleteness theorems (1931) showed that a comprehensive consistency proof for complex systems like arithmetic is impossible, generally demonstrating that the program's original, ambitious goals could not be fully achieved.
  • Legacy: Despite its limitation by Gödel, the program significantly influenced modern proof theory, leading to "relativized" Hilbert programs that explore weaker forms of consistency.

Formal System

A formal system is considered consistent if it is free from contradiction, meaning it is impossible to derive both a statement and its negation ((P) and (\neg P)) from its set of axioms. A consistent system cannot prove every statement, ensuring that not all formulas are theorems. Consistency is often interpreted as having at least one model.

Key Aspects of Consistency in Formal Systems:

  • No Contradiction: A system is consistent if there is no formula $$S$$ such that both $$S$$ and $$\neg S$$ (not $$S$$) are provable.
  • Significance: If a system is inconsistent, every statement becomes provable, rendering it useless.
  • Model Existence: A system is consistent if and only if it has a model, which is a structure that satisfies all of its axioms.
  • Gödel's Incompleteness Theorems: A sufficiently powerful, consistent formal system (like Peano arithmetic) cannot prove its own consistency.
  • Relative Consistency: Sometimes, a system's consistency can only be proven relative to another system (e.g., ZFC + "there exists an inaccessible cardinal" proves ZFC is consistent).

In essence, a consistent system ensures that truth cannot lead to falsity, maintaining the integrity of its theorems.

The Halting Problem

The halting problem is a fundamental, undecidable problem in computer science, proven by Alan Turing in 1936, which states that it is impossible to create a universal algorithm that can determine whether any given program will eventually halt (finish) or run forever on a specific input. It proves there are limits to what computers can solve.

Whatch this video: https://www.youtube.com/watch?v=VyHbd6sx5Po

Key Aspects of the Halting Problem:

  • Definition: Given an arbitrary program and an input, can you decide if the program will finish running or run in an infinite loop?
  • Undecidability: There is no general program $$H$$ that can analyze all possible program-input pairs and correctly predict if they halt.
  • The Proof (Contradiction): If a "halting checker" algorithm $$H$$ existed, a paradoxical program could be created that calls $$H$$ and does the opposite of its prediction — if $$H$$ predicts it halts, the program loops forever; if $$H$$ predicts it loops, the program halts.
  • Significance: It serves as a foundational proof that certain problems are computationally impossible, affecting fields like compiler optimization and software verification.
  • Impact: The halting problem is "undecidable," meaning no algorithm can reliably determine this for every case.

This video provides a more in-depth explanation of the proof that the halting problem is unsolvable: https://www.youtube.com/watch?v=macM_MtS_w4

The concept proves that even with infinite memory and time, computers cannot solve every problem, providing a definitive boundary for computer science.

Is bug-free provable?

The Halting Problem is fundamentally linked to the impossibility of proving that an arbitrary piece of software is free from bugs. The inability to create a "perfect" bug-checker is a direct consequence of the mathematical impossibility of solving the Halting Problem.

The Core Connection: Rice's Theorem

While the Halting Problem (Turing, 1936) specifically states that you cannot write a program that determines whether any given program will eventually halt or run forever, it was later generalized by Rice's Theorem.

  • Rice's Theorem states that any non-trivial, semantic property of a program is undecidable.
  • A "semantic property" is anything related to the program's behavior (e.g., "does this program ever output '42'?" or "does this program throw a null pointer exception?").
  • Because being "bug-free" is a non-trivial semantic property, it is mathematically impossible to write an algorithm that can analyze any arbitrary program and determine if it is free from bugs.

How the Halting Problem Causes Unverifiable Code

The inability to solve the Halting Problem (determining if a loop ever ends) means we cannot generally know if a program will:

  • Enter an infinite loop (a common bug).
  • Reach an error state.
  • Free allocated memory.

If we could prove a program was bug-free, we could also solve the Halting Problem (e.g., by writing a program that checks if another program terminates, then checking if that checker is bug-free), which we know is impossible.

Practical Implications (Why We Use Testing)

Because perfect, automated verification is mathematically impossible, software engineering relies on approximations:

  • Static Analysis Tools: These scan code for bugs but often produce "false positives" or miss issues because they use heuristics rather than perfect analysis.
  • Testing: Instead of proving code works, we use testing to show it works for specific inputs.
  • Formal Verification: While you cannot prove all programs are bug-free, you can formally prove that specific, simple, or critical algorithms are correct.

Summary

The Halting Problem proves that a general, perfect debugger cannot exist. We cannot create a tool that takes any software and guarantees "no bugs." This makes software analysis a field of approximations rather than absolute mathematical certainty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment