In this and the following coding exercises, we'll look at the three-bit repetition algorithm.

In this exercise, you are given a function called encode that creates three copies of a bit : . Create a function called noisy_channel that flips each bit with an equal and independent probability . For example, if the repeated bit string is , then the flipped bit string could be, say, , where only the first bit was flipped and the other two are safe. This is going to be the message that Bob receives from Alice.

You have numpy — imported as np in the code — to use.

Hint.

Use np.random.uniform(0, 1) to see whether or not a bit will get flipped. This will generate a random number between and . If this number is greater than , then the bit doesn't get flipped.

Also, the ^ operator in Python might be useful. See here for more details.

or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Explain why error correction is important.
  • Explain and implement the three-bit classical repetition code.