ArticleslgStudy

science

Locally testable code

Locally testable code is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Locally testable code rather than just read about it. In short: A locally testable code is a type of error-correcting code for which it can be determined if a string is a word in that code by looking at a small (frequently constant) number of bits of the string. In some situations, it is useful to know if the data is corrupted without decoding all of it so that appropriate action can be taken in response.

Key takeaways

  • Locally testable code belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Locally testable code to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Locally testable code from memory before moving on to harder problems.

Reference excerpt

A locally testable code is a type of error-correcting code for which it can be determined if a string is a word in that code by looking at a small (frequently constant) number of bits of the string. In some situations, it is useful to know if the data is corrupted without decoding all of it so that appropriate action can be taken in response. For example, in communication, if the receiver encounters a corrupted code, it can request the data be re-sent, which could increase the accuracy of said data. Similarly, in data storage, these codes can allow for damaged data to be recovered and rewritten properly. In contrast, locally decodable codes use a small number of bits of the codeword to probabilistically recover the original information. The fraction of errors determines how likely it is that the decoder correctly recovers the original bit; however, not all locally decodable codes are locally testable. Clearly, any valid codeword should be accepted as a codeword, but strings that are not codewords could be only one bit off, which would require many (certainly more than a constant number) probes. To account for this, testing failure is only defined if the string is off by at least a set fraction of its bits. This implies words of the code must be longer than the input strings by adding some redundancy.

Definition To measure the distance between two strings, the Hamming distance is used

Δ(x,y)=|{i:xi≠yi}| The distance of a string w from a code C:{0,1}k→{0,1}n is computed by

Δ(w,C)=minx{Δ(w,C(x))} Relative distances are computed as a fraction of the number of bits

δ(x,y)=Δ(x,y)/n and δ(w,C)=Δ(w,C)/n A code C:{0,1}k→{0,1}n is called q-local δ-testable if there exists a Turing machine M given random access to an input w that makes at most q non-adaptive queries of w and satisfies the following:

For any x∈{0,1}k and w=C(x), Pr[Mw(1k)=1]=1. In other words, M accepts given access to any codeword of C. For w∈{0,1}n such that δ(w,C)>δ, Pr[Mw(1k)=1]≤1/2. M must reject strings δ-far from C at least half the time. Also the rate of a code is the ratio between its message length and codeword length

r=|x||C(x)|

Limits It remains an open question whether there are any locally testable codes of linear size, but there are several constructions that are considered "nearly linear":

Polynomial arbitrarily close to linear; for any ϵ>0, n=k1+ϵ. Functions of the form n=k1+ϵ(k), where ϵ(k) is a function tending toward 0. This makes n closer to linear as k increases. For example: 1/log⁡log⁡k 1/(log⁡k)c for some c∈(0,1) exp⁡((log⁡log⁡log⁡k)c)/log⁡k for c∈(0,1) These have both been achieved, even with constant query complexity and a binary alphabet, such as with n=k1+1/(log⁡k)c for any c∈(0,1). The next nearly linear goal is linear up to a polylogarithmic factor; n=poly(log⁡k)∗k. Nobody has yet to come up with a linearly testable code that satisfies this constraint. In November 2021 two preprints have reported the first polynomial-time construction of "c3-LTCs" namely locally testable codes with constant rate r, constant distance δ and constant locality q.

Connection with probabilistically checkable proofs Locally testable codes have a lot in common with probabilistically checkable proofs (PCPs). This should be apparent from the similarities of their construction. In both, we are given q random nonadaptive queries into a large string and if we want to accept, we must with probability 1, and if not, we must accept no more than half the time. The major difference is that PCPs are interested in accepting x if there exists a w so that Mw(x)=1. Locally testable codes, on the other hand, accept w if it is part of the code. Many things can go wrong in assuming a PCP proof encodes a locally testable code. For example, the PCP definition says nothing about invalid proofs, only invalid inputs. Despite this difference, locally testable codes and PCPs are similar enough that frequently to construct one, a prover will construct the other along the way.

Examples

Hadamard code One of the most famous error-correcting codes, the Hadamard code, is a locally testable code. A codeword x is encoded in the Hadamard code to be the linear function f(y)=∑ixiyi (mod 2). This requires listing out the result of this function for every possible y, which requires exponentially more bits than its input. To test if a string w is a codeword of the Hadamard code, all we have to do is test if the function it encodes is linear. This means simply checking if w(x)⊕w(y)=w(x⊕y) for x and y uniformly random vectors (where ⊕ denotes bitwise XOR). It is easy to see that for any valid encoding w, this equation is true, as that is the definition of a linear function. Somewhat harder, however, is showing that a string that is δ-far from C will have an upper bound on its error in terms of δ. One bound is found by the direct approach of approximating the chances of exactly one of the three probes yielding an incorrect result. Let A, B, and C be the events of w(x), w(y), and w(x⊕y) being incorrect. Let E be the event of exactly one of these occurring. This comes out to

P(E)≥P(A∪B∪C)−3∗P(A∪B)≥3∗P(A)−3∗P(A∪B)−3∗P(A∪B)≥3δ−6δ2 This works for 0<δ≤5/16, but shortly after, 3δ−6δ2<δ. With additional work, it can be shown that the error is bounded by

f(x)={3δ−6δ2:0≤δ≤5/1645/128:5/16≤δ≤45/128δ:45/128≤δ≤1/2 For any given δ, this only has a constant chance of false positives, so we can simply check a constant number of times to get the probability below 1/2.

Long code The Long code is another code with very large blowup which is close to locally testable. Given an input 0≤i≤2k (note, this takes k bits to represent), the function that returns the ith bit of the input, fi(x)=xi, is evaluated on all possible 2k-bit inputs 0≤x≤22k, and the codeword is the concatenation of these (of length n=22k). The way to locally test this with some errors is to pick a uniformly random input x and set y=x, but with a small chance of flipping each bit, μ>0. Accept a function f as a codeword if f(x)=f(y). If f is a codeword, this will accept f as long as xi was unchanged, which happens with probability 1−μ. This violates the requirement that codewords are always accepted, but may be good enough for some needs. Other locally testable codes include Reed-Muller codes (see locally decodable codes for a decoding algorithm), Reed-Solomon codes, and the short code.

See also Gilbert–Varshamov bound Hamming code Expander code

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Locally testable code

Start with the simplest possible case. Write down what Locally testable code claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Locally testable code before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Locally testable code ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Locally testable code

In research
Locally testable code appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Locally testable code in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Locally testable code is common in secondary-school and first-year university syllabi. It links to neighbouring topics Error detection and correction, so understanding it makes those chapters shorter.
In everyday life
Look for Locally testable code outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Locally testable code” →

How to study Locally testable code in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Locally testable code means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Locally testable code out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Locally testable code in simple terms?

A locally testable code is a type of error-correcting code for which it can be determined if a string is a word in that code by looking at a small (frequently constant) number of bits of the string. In some situations, it is useful to know if the data is corrupted without decoding all of it so that…

Why does Locally testable code matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Locally testable code?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Locally testable code.

Tags

  • Error detection and correction

Keep exploring