CS245 - Discrete Structures I: Chapter 4 - Proofs and Error-Correcting Codes
Hierarchy of Modern Systems and the Role of Abstraction
Modern Computer Systems Architecture: Systems are constructed as a "tower" of stacked layers. Each individual layer is dependent on the layer immediately beneath it to function correctly.
Real-World Example: A financial transaction on a website relies on a specific hierarchy: * The Website layer. * Networking technologies such as , , and . * Software on the device (Browser). * The Operating System (OS). * Physical Hardware.
The Principle of Abstraction: This fundamental computer science concept allows users and designers to interact with a layer without needing to understand the internal complexities of layers below it. As long as a layer performs its defined job correctly, other layers can build upon it.
A Tower of Trust: Mathematical proofs serve as the foundation of this trust. * Definition of a Proof: A convincing argument that establishes a specific claim as a fact. * The Goal of Proofs: To derive new facts from existing, established facts while successfully persuading the reader of the validity of the new fact.
Fundamental Concepts of Error-Correcting Codes
Transmission Process Model: * A sender intends to transmit a message consisting of bits. * The message is converted into a longer -bit codeword () through an encoding process using a code (the set of all valid codewords). * During transmission, the codeword travels through a noisy channel where it may be corrupted, resulting in a received bitstring . * The receiver utilizes a decoding process on to produce a recovered message .
The Ultimate Goal: If the degree of corruption/noise is sufficiently small, the system should ensure that the recovered message is identical to the original message ().
Code Types: * Error-detecting codes: These systems can determine if corruption has occurred during transmission but cannot necessarily fix it. * Error-correcting codes: These systems can both detect that corruption happened and successfully recover the original uncorrupted message.
The Role of Redundancy: Both systems work by adding extra bits to the original data. This redundancy allows for reliable transmission and storage even in environments prone to data corruption, such as deep-space satellite transmissions susceptible to radiation.
Case Study: Error Detection in Credit Card Numbers
Scope and Scale: Visa and Mastercard use -digit numbers. Out of all possible combinations, only approximately are valid.
The Check Digit: Validity is determined by a specific arithmetic calculation. If you know any digits of a card, the th digit (called the "check digit") is mathematically determined.
Luhn Algorithm (The mod 10 algorithm): Designed to detect common typing mistakes including a single wrong digit, two swapped digits, or single-digit errors. * Step 1: Starting from the second-to-last digit and moving left, double every second digit. * Step 2: If the result of doubling is greater than , add the two digits of the result together (e.g., ; ). * Step 3: Sum all modified digits, the digits that were not doubled, and the check digit. * Step 4: Check if the total sum is divisible by . A valid number satisfies: .
Numerical Example 1 (Valid): * Card: * Doubling every second digit from right: * Adjusting results : * Sum: * is divisible by , so the number is valid.
Numerical Example 2 (Invalid): * Card: * Adjusted digits: * Sum: * The value . Since it is not , the number is invalid.
Hash Functions and Checksums
Hash Functions: Map data of arbitrary length to a fixed-size output (the hash value or ). * Mechanism: The sender transmits the message and the hash value . The receiver calculates the hash of the received message . If , the message is likely correct. If , an error is detected. * Capability: Hashes only detect errors; they do not correct them. Cryptographic hashes like can detect even a single-bit change with extremely high probability.
Checksums: A method used for file transfers. A large file is broken into -bit blocks. The blocks are transmitted, followed by a final block representing the bitwise of all previous blocks to verify integrity.
Hamming Distance
Definition: Let be two -bit strings. The Hamming distance, denoted , is the count of positions where the bits differ: .
Constraint: The distance is undefined if the strings are of different lengths.
Calculation Examples: * (Positions 1 and 2 differ). * (Only position 2 differs). * (All four bits differ). * (Matches perfectly).
Mathematical Properties (Metric Properties): For all bitstrings : * Reflexivity: if and only if . * Symmetry: . * Triangle Inequality: .
Codes, Messages, and Codewords
Formal Definition of a Code: A code is a set , where for some integer .
Terminology: * Message: Any element of . * Codeword: Any element belonging specifically to the set .
Example Case: A code defined as . * , so the message length is . Possible messages are . * Codewords have length . * This is categorized as a code.
Redundancy Calculation: In the example, instead of sending bits, the sender transmits bits. The extra bits facilitate error management.
Decoding and Errors
Nearest Neighbor Decoding: If a received bitstring is not in the code, the receiver calculates the distance to all valid codewords and chooses the one with the smallest Hamming distance. * Scenario: Receive . * * * * * Conclusion: Decode as message corresponding to (message ).
Operational Dangers: * Error Detection Failure: A codeword is corrupted into , but happens to be a separate valid codeword in . The system reports "no error." * Error Correction Failure: A codeword is corrupted into , and is closer to an incorrect codeword than it is to .
Minimum Distance and Error Theorems
Minimum Distance (): The smallest Hamming distance between any two distinct codewords in : .
Code Rate: The ratio between message length () and codeword length (): . This measures efficiency.
Trade-off: Higher distance () increases reliability but typically requires more bits, lowering the rate (efficiency).
Theorem 4.6 (Detection and Correction): Let be a code with minimum Hamming distance . * The code can detect up to errors. * The code can correct up to errors.
Specific Odd Distance Theorem: If minimum distance is , it detects errors and corrects errors. * Example : . Detects , corrects . * Example : . Detects , corrects . * Example : Detects , corrects .
Formal Proof Logic for Theorem 4.6
Error Detection Proof (Informal): If the minimum distance is , any corruption of up to bits cannot result in another valid codeword because reaching another codeword requires at least flips. Thus, we always identify the error.
Error Correction Proof (Formal): * Transmitted codeword , received bitstring , where . * Consider any other codeword . * Using triangle inequality: . * Substitute known bounds: . * Since and , the received string is mathematically closer to the original codeword than any other codeword.
Repetition Codes
Mechanism: Encode a message by repeating its bits times.
Example: A -Repetition code for message results in codeword .
Lemma 4.11: A Repetition code has: * . * .
Proof by Construction: To show code existence (e.g., a code with ), we explicitly build the Repetition code.
The Hamming Code
Concept: Uses multiple parity bits derived from subsets of the message bits to provide better efficiency than repetition codes while maintaining error protection.
Parity Function: . * Value is if there are an odd number of s; value is if even.
Hamming (7,4) Code: Encodes a -bit message into a -bit codeword: .
Performance vs. Repetition: * Repetition (): Codeword length , Distance , Rate . * Hamming (7,4): Codeword length , Distance , Rate .
Optimality: * Theorem 4.8 (Better News): A code exists with . * Theorem 4.9 (Bad News): There is no code with with a rate strictly better than . The Hamming code is the theoretical best rate for these parameters.
Questions & Discussion
Decoding Problem: Given the following Hamming (7,4) received codewords (assuming at most one error in each): * * * * * Task: Identify the original messages based on the encoding scheme provided in the tables and logic above.