Clowder

From Esolang
Jump to navigation Jump to search

Clowder is an esoteric programming language for describing Quantum Circuits in the style of OpenQASM. It is a small simple language inspired by esoteric programming languages COW and Brainfuck. One of the most famous quantum thought experiments is Schrodinger's Cat. A quantum circuit built of cats would need more than one cat to do any significant computation. A group of cats is called a clowder.

This language was invented by Mark Boady of Drexel University in 2025.

Language Overview

All commands are the word "mew" with different capitalizations. Some commands take one numerical value as input. This value is written as a series of "meow" instructions with varying capitalization. Whitespace is ignored and all other text is considered comments.

Mathematical Introduction

A quantum circuit can be envisioned as a collection of cats in a box.

As a first example, we start with only one cat. The cat is initially in the alive state. We apply a quantum process that may or may not kill the cat. This places the cat in a superposition between life and death. As long as the box is not opened, the cat is both alive and dead.

The initial state of our cat is alive.

In general, the cat has two values, one representing aliveness and one representing deadness. Both are complex numbers.

The probability the cat will be found alive when the box is opened is . The probability the cat will be found alive when the box is opened is .

Since the cat must be either alive or dead when the box is opened, we must have . There is a 100% chance the cat is alive or dead when the box is opened.

Once the cat has been placed in the box, actions can be performed on the cats. These are called gates and represented by unary matrices.

If we want to switch our cat into a 50% alive and 50% dead state we would apply a Hadamard Gate. This is the classic Schrodinger's Cat thought experiment. The cat is based in a box where a it will be poisoned by a quantum process 50% of the time. Until the box is opened the cat is both alive and dead.

Since, , we can see there is a 50% chance of each outcome.

With additional cats in the box, we can create coherence. For example, if the first cat dies then the second cat lives. This creates a relationship between two cats. These relationships are critical to creating quantum circuits.

When multiple cats appear in the circuit, the state of the cats is a vector. With cats, the vector has positions. At each stage of computation, a by matrix is applied. A command must be given for each cat. The commands are merged into a matrix using tensor products.

The first cat in the circuit is referred to as the lowest order cat. The last cat is the highest order cat. The cats are given for alive and for dead starting from the highest order and ending on the lowest order. This means the commands are written in the opposite order the alive/dead status is read.

A two-cat system is a 4 position vector. Both cats start alive.

Imagine we want to do nothing to the highest order cat. We can apply the identity.

We want to put the lowest order cat into a 50% alive / 50% dead superposition.

The matrix applied to the cats is computed below.

This matrix is applied to the two-cat vector.


The lowest order cat is now both alive and dead. Flipping the order of the tensor product switches which cats is alive and dead.

We apply this matrix to the same initial vector.

The lowest order cat is always alive but the highest order cat is both alive and dead.

Adoption

All programs start with one special command. This must be the first non-comment command in the file.

A quantum circuit has a fixed number of cats. The number of cats must be set before any commands can be executed. All cats start in the alive state. No cats can be added or removed once the circuit begins. At the end of the circuit, the box is opened and the cats are determined to be dead or alive.

To set the number of cats in the circuit, the following command is required. The command is case insensitive. Replace x with any natural number.

Adopt x cats.

If we want 4 cats in our system, then the command would be

Adopt 4 cats.

This command must be given before any mew or meow instructions.

Note that this is the only command that is case insensitive and uses natural numbers. This is because it is about the cats, not giving instructions that act on the cats.

Commands

Commands in the quantum circuit are represented by unary matrices. The control-x gate is slightly special because it connects two cats. It is described below the instruction table.

Instructions must be given in multiples of the number of cats adopted. For example, if you have adopted 3 cats, then you must give instructions in multiples of 3. Each cat must be given an instruction at each point in the circuit. A group of commands for cats is called a command block.

Instruction Command Inputs Meaning Matrix
0 mew 1 Rx(theta)
1 meW 1 Ry(theta)
2 mEw 1 Rz(phi)
3 mEW 1 P(theta)
4 Mew 0 CX control cat see below
5 MeW 0 CX target cat see below
6 MEw 0 I
7 MEW 0 H

The Mew and MeW commands must be paired, but which comes first doesn't matter. Whichever is read first will always pair with the next matching one. If you give the target first, it will match with the next control found in the same command block. If you start with the control, it will match the next target. Both must appear in the same command block. If you have 5 cats in your circuit, both must appear in the same 5 command block.

The paired commands work as follows. If the control cat is alive, no action is taken. If the control cat is dead, the alive and dead values of the target cat are swapped. In a two-cat system the matrix is given below. In this system, the lowest order cat controls the highest order cat. A generic vector is show as an example of how the positions flip. This flip can be generalized for any control and target cats in the system.

Numerical Representations

The meow instruction is used to provide input to those commands that require it. If no meow instructions are given, the command treats it as an input of 0.

Any number of meow commands may be given as input. They will all be read and parsed as one floating point number.

Upper case letters are read as binary 1 and lower case letters are read as binary 0.

Since the word meow has 4 letters, the number of bits must be a multiple of 4. The number is read in two parts. The first of the bits are the base and the remaining are treated as exponent . The number is computed as .

The calculation is shown by example below.

The example instruction is MeOWmeoW. This is 8 bits. That means the base is 6 bits and the exponent is 2 bits. The base is MeOWme which is read as 101100. The exponent is oW which is read as 01.

The numbers are read as traditional binary.

If the first digit is 1, then the number is treated as two's complement. Subtract the largest number that can be represented in that number of bits to get a negative.

Now that we have the base and exponent, we can compute the value.

If the exponent is exactly one bit, it will be read as 0 or 1 directly. Two's complement is only considered for binary values with more than one bit.

Example Programs

The following code shows the Deutsch-Josza algorithm on a single CX gate. The lowest order cat will always be dead, but the highest order cat is alive 50% of the time. The circuit can be visualized below.

       ┌───┐  ┌───┐     ┌───┐┌─┐   
q_0: ──┤ I ├──┤ H ├──■──┤ H ├┤M├───
     ┌─┴───┴─┐├───┤┌─┴─┐├───┤└╥┘┌─┐
q_1: ┤ Rx(π) ├┤ H ├┤ X ├┤ I ├─╫─┤M├
     └───────┘└───┘└───┘└───┘ ║ └╥┘
c: 2/═════════════════════════╩══╩═
                              0  1 

The program uses whitespace to break up the gates. I used C style commenting to differentiate comments from code, but this is not required.

Adopt 2 cats.

MEw //Identity on lowest cat
mew mEoWMEoWMeOwmeowmEOWmeOWmeOwmEOwMEOWMEOWmEOW 
//traditional X gate (rotate Pi radians around X axis)
//Pi = 3141592653*10^(-9)

MEW //H on lowest cat
MEW //H on highest cat

Mew //Lowest cat controls the X
MeW //Highest cat is target for X

MEW //H on lowest cat
MEw //Identity on highest cat

//At this point lowest cat should be dead
//100% of the time.

//The highest order cat should be in 
//a 50/50 superposition between alive and dead.

//In a Deutsch-Josza circuit, we don't 
//actually care about the highest order cat.

External resources