作者: Chloé Lourseyre
编辑: Peter Fordham
许可: CC-BY 4.0
原文: https://belaycpp.com/2021/11/24/is-my-cat-turing-complete/
Is my cat Turing-complete?
NOVEMBER 24, 2021CHLOÉ `SENUA` LOURSEYRE
This article is an adaptation of a Lightning Talk I gave at CppCon2021. A link to the video will be given here as soon as it’s available.
I'll touch on a lighter subject this week, nonetheless quite important: is my cat Turing-complete?
Meet Peluche
Peluche (meaning “plush” in French) is a smooth cat that somehow lives in my house.
She will be our test subject today.
Is Peluche Turing-complete?
What is Turing-completeness
Turing-completeness is the notion that if a device can emulate a Turing machine, then it can perform any kind of computation1.
It means that any machine that implements the eight following instructions is a computer (and can thus execute any kind of computation):
-
.
and,
: Inputting and outputting a value -
+
and-
: Increase and decrease the value contained in a memory cell2. -
>
and<
: Shift the current memory tape left or right. -
[
and]
: Performing loops.
So, if Peluche can perform these eight instructions, we can consider her Turing-complete.
Proof of the Turing-completeness
Input and output
First, I tried to poke Peluche if I could get a reaction.
She looked at me, then just turned around.
So here it is: I poked her, and I got a reaction. So she can process inputs and give outputs.
Input/output confirmed!
Increase and decrease memory value
The other day, I came back from work to this:
Kibbles everywhere;
But then I took a closer look and realized that the slabs could be numbered, like this:
This looks pretty much like a memory tape to me! Since she can spill kibbles on the tiles and then eat them directly from the floor, she can increase and decrease the values contained in a given memory cell.
Increase/decrease confirmed!
Shift the current memory cell left or right
Another time, I was doing the dishes and inadvertently spilled some water on Peluche. She began to run everywhere around the kitchen, making a huge mess.
If you look close (at the tip of the red arrow), you may notice that while making this mess, she displaced her bowl.
Displacing her bowl means she will spill her kibbles in another tile. This counts as shifting the memory head to edit another memory cell.
Shift of the memory tape confirmed!
Perform loops
So, after this mess, I (obviously) had to clean up.
No more than five minutes later, I went back to the kitchen to this:
Yeah… she can DEFINITELY perform loops…
Loops confirmed!
We have just proven that Peluche is, indeed, Turing-complete. So now, how can we use her to perform high-performance computations?
What to do with her?
Now that I’ve proven that Peluche is Turing-complete, I can literally do anything with her!
Thus, I tried to give her simple code to execute3: