Semi-quantum

From Esolang
Jump to navigation Jump to search

Semi-quantum is an esoteric programming language invented in 2015 by an anonymous user. It allows the user to chose between "classical" programming, in a similar manner to brainfuck, and quantum programming, similar to Quantum Dimensions. The idea was derived from languages that allow both imperative and object-oriented programming, only in this case it is classical and quantum programming.

Setup

The program has a three-dimensional space (similar to brainfuck's data tape, only in three dimensions) where numbers, characters and qubits can be stored. Each dimension is infinite in size. A pointer starts at (0,0,0). Each point in the space is called a cell. Each cell starts at zero. Because each qubit can only represent one digit, a binary list exists. This is a 1D reserved piece of memory, where qubit measurements can be built up into a binary number. The binary list is initially all zeroes.

Moving

  • P(x,y,z) moves the pointer to the cell with the co-ordinates (x,y,z).
  • C(x,y,z) moves the contents of the cell to the cell with co-ordinates (x,y,z). The contents of the target cell are destroyed.

Loops

  • [ if the cell under the pointer is empty, jump to the instruction immediately after the next ] instruction. Otherwise, continue.
  • ] jump back to the most recent [ instruction.

Loops cannot be nested.

Classical

  • + increment the current cell
  • - decrement the current cell
  • /(character)/ stores (character) in the current cell e.g. /p/

Quantum

Defining a qubit

  • (p~q) stores the qubit a|0> + b|1> in the current cell, where a = cos(p/2) and b = (e^(iq))*(sin(p/2)). q is the angle (in radians) of phase of the qubit and p is the angle (in radians) between the qubit and the |0> axis of a Bloch sphere.

Quantum entanglement

  • {(a,b,c)$(x,y,z)} entangles the qubits at the co-ordinates. The qubit at (a,b,c) is unchanged and the qubit at (x,y,z) becomes NOT(a,b,c). The condition (x,y,z)= NOT(a,b,c) is maintained until the qubits are disentangled.
  • {%(a,b,c)} disentangles the qubit at (a,b,c) with whatever qubit it is entangled with.

Quantum transformations

These are the quantum transformations that are available.

Hadamard

  • {H} performs the Hadamard transformation on the current qubit.

Pauli X

  • {X} perform the Pauli X (NOT) transformation on the current qubit.

Pauli Y

  • {Y} performs the Pauli Y transformation on the current qubit.

Pauli Z

  • {Z} performs the Pauli Z transformation on the current qubit.

Phase shift

  • {Pp} performs a phase shift of p radians on the current qubit e.g. {P2}

CNOT

  • {(x,y,z)C} performs the CNOT transformation on the current qubit, using the qubit at (x,y,z) as a control.

SWAP

  • {S(x,y,z)} performs the SWAP transformation on the current qubit and the one at (x,y,z).

Fredkin

  • {(a,b,c)F(x,y,z)} performs the Fredkin transformation on the current qubit and the one at (x,y,z), using the one at (a,b,c) as a control.

Toffoli

  • {(a,b,c)(x,y,z)T} performs the Toffoli transformation on the current qubit, using the ones at (a,b,c) and (x,y,z) as controls.

Define your own

def {name}{total number of qubits}
{first line of transformation matrix}
{second line of transformation matrix}
{etc.}
{number of control qubits}

The definition is placed before the main line of code. The name cannot be T, F, S, C, P, X, Y, Z, H, $ or % as these are already in use.

Input and output

Input

  • & ask for a character, then store it in the current cell.
  • @ ask for p, then ask for q. Store the qubit (p~q) in the current cell.

Output

  • ! if the current cell contains a character, output it. If it contains a qubit, measure it and print the result to the binary list.
  • ? output the numerical value of the binary list.
  • £ output the ASCII value of the binary list.
  • ¬ if the current cell contains a qubit, show it's state in the form a|0> + b|1>, without destroying the superposition. Otherwise, do nothing.