https://belaycpp.com/2021/11/24/is-my-cat-turing-complete/ Skip to content [icon-small] Belay the C++ A weekly blog talking about (usually bad) practices in C++ Primary Menu Menu * Home * Articles + All articles + History of C++ * Team * Contact * Francais Is my cat Turing-complete? November 24, 2021Chloe `Senua` Lourseyre Author: Chloe Lourseyre Editor: Peter Fordham 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. [1123144030] 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 computation^1. 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 cell^2. * > 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. [1123144030] [1123144030] She looked at me, then just turned around. [1123144030] [1123144030] 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: [1123144030] Kibbles everywhere... But then I took a closer look and realized that the slabs could be numbered, like this: [1123144030] 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. [1123144030] 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: [1123144030] 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 execute^3: The result was final: she wouldn't do a thing. Though they can, maybe cats are not designed to execute code after all? About "cat-computing" Jokes aside, cat-computing is the name I give to this generalized practice. In my experience, it happens quite often that when someone discovers a new feature of a language, they begin to use it everywhere, just because they can and they want to. However, just like you can execute code using a cat^4 but shouldn't, it's not because you can use a feature that you should. They were too busy wondering if they could to think about whether they should. Dr Ian Malcolm, Jurassic Park Wrapping up Cat-computing seems to be a rookie mistake (and it is), but even the most experienced developers sometimes make rookie mistakes (and there's no shame in that). Every three years, a new version of C++ is published. Every time, it makes me want to use the new features in every possible situation. Though this is a good opportunity to build some experience around that (one of the best ways to avoid misuses of a feature is to perform these misuses once, in my opinion), this is also favorable ground for acquiring bad practices. Always ask yourself if a feature is necessary^5 before using it, or else you may do cat-computing. Also, cat-computing is animal abuse, so don't do it . Thanks for reading and see you next week! (No cats were harmed during the writing of this article, but one was gently poked.) Author: Chloe Lourseyre Editor: Peter Fordham [1123144030] Addendum Notes 1. This is a simplified definition, very inaccurate but accurate enough for this example. If you want the real definition, go there: Turing completeness - Wikipedia 2. I did not state it explicitly, but a Turing machine has a "memory tape" with "memory cells" on it. The machine is always pointing to a memory cell, which is the mentioned "current" memory cell. 3. You may not be able to read this sample of code -- this is a fancy new language I designed called "braincat". 4. Actually, you can't execute code using a cat, I know, but it's for the sake of the metaphor that I assume you can. 5. Of course, necessity occurs when there is a known benefit to the feature. I'm not talking about "absolute necessity" but about "practical necessity". Share this: * Twitter * Facebook * Like this: Like Loading... Related Categories: Bad practice Tags: Peter Fordham (Editor) Post navigation - Duff's device in 2021 8 thoughts on "Is my cat Turing-complete?" 1. Pingback: Is my cat Turing-complete? - MadGhosts 2. Pingback: Is my cat Turing-complete? - The web development company 3. [x9Z24E] Genetix [?][?][?] Vaccinee 2/2 (@GenetixVideos) says: November 24, 2021 at 3:37 pm Dommage que je n'ai pas pu tester sur mon chat Unix, j'aurais pu verifier si elle etait Turing Complet LikeLike Reply 4. [2f0d6f] Michel Gomes says: November 24, 2021 at 3:43 pm I thought it was just amazing and fun I will try with my cat LikeLike Reply 5. [5b687c] rharvest says: November 24, 2021 at 4:36 pm LikeLike Reply 6. [23bea3] dvtn khn says: November 24, 2021 at 7:00 pm One problem with cats is that they are non-deterministic. Often the same input leads to a different output. Just like the wife's Windows machine, this can sometimes be attributed to a virus or worm. LikeLike Reply 7. [ecace7] Joseph C. Sible says: November 24, 2021 at 7:28 pm Here's a little transpiler for braincat: tr '' '> LikeLike Reply 1. [ecace7] Joseph C. Sible says: November 24, 2021 at 7:50 pm Huh, apparently if you try to post a left angle bracket, it makes the rest of your comment disappear. Anyway, here's the part of my post that got cut off after that: .[]+-' LikeLike Reply Leave a Reply Cancel reply Enter your comment here... [ ] Fill in your details below or click an icon to log in: * * * * Gravatar Email (required) (Address never made public) [ ] Name (required) [ ] Website [ ] WordPress.com Logo You are commenting using your WordPress.com account. ( Log Out / Change ) Google photo You are commenting using your Google account. ( Log Out / Change ) Twitter picture You are commenting using your Twitter account. ( Log Out / Change ) Facebook photo You are commenting using your Facebook account. ( Log Out / Change ) Cancel Connecting to %s [ ] Notify me of new comments via email. [ ] Notify me of new posts via email. [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] Last articles * Is my cat Turing-complete? * Duff's device in 2021 * Pragma: once or twice? * [History of C++] The genesis of casting. * [History of C++] Templates: from C-style macros to concepts * [History of C++] Explanation on why the keyword `class` has no more reason to exist Subscribe via Email You'll be updated about new articles Email Address: [ ] Subscribe Creative Commons License Belay the C++ and all its articles is licensed under a Creative Commons Attribution 4.0 International License. Create a website or blog at WordPress.com * Follow Following + [croppe] Belay the C++ Join 48 other followers [ ] Sign me up + Already have a WordPress.com account? Log in now. * + [croppe] Belay the C++ + Customize + Follow Following + Sign up + Log in + Copy shortlink + Report this content + View post in Reader + Manage subscriptions + Collapse this bar Loading Comments... Write a Comment... [ ] Email (Required) [ ] Name (Required) [ ] Website [ ] [Post Comment] %d bloggers like this: [b]