Quantum INTERCAL

From Esolang
Jump to: navigation, search

Quantum INTERCAL was first introduced by CLC-INTERCAL version 0.04. It is based on a very simple idea: when you ABSTAIN FROM or REINSTATE a statement, you are really changing the value of a single bit, which records whether the statement should be executed or not. Similarly, for IGNORE and REMEMBER. Now replace this bit with a quantum bit. As soon as you do anything which may change this bit, your program will exist in a superposition of two quantum states, one in which the statement is ABSTAINed FROM, and one in which it is REINSTATEd.

The above discussion naturally suggested a syntax to distinguish between normal ABSTAIN FROM/REINSTATE and the quantum version: compare the following statements:

  1. DO ABSTAIN FROM (1)
  2. PLEASE REINSTATE (1)
  3. DO ABSTAIN FROM (1) WHILE REINSTATING IT
  4. PLEASE REINSTATE (1) WHILE ABSTAINING FROM IT

The first two statements are non-quantum, the next two are quantum. Incidentally, the two quantum statements listed are entirely equivalent, they both result in a quantum bit which is 50% true and 50% false. The matter becomes complicated if you use a non-quantum statement to set a bit which was previously set by a quantum statement; the interested reader can just write such a program, feed it to the compiler and see what happens. Alternatively, the theory of quantum superposed states can be applied to see what it has to say.

Version 1.-94 of CLC-INTERCAL greatly extended the quantum possibilities. Now every statement which can modify data has a quantum version. For example, the statement:

    DO .1 <- #2 WHILE NOT ASSIGNING TO IT

is equivalent (more or less) to:

    PLEASE IGNORE .1 WHILE REMEMBERING IT
    DO .1 <- #2
    DO REMEMBER .1

Interaction between Quantum INTERCAL and other extensions of CLC-INTERCAL can be a bit weird sometimes, and will be discussed when my head stops spinning

Note that googling "Quantum INTERCAL" returns references to a program in which multiple COME FROMs all pointing at the same label will cause a program to create superposed quantum states. Whoever wrote that was confusing Quantum INTERCAL with Threaded INTERCAL

Also note that a quantum superposition of states is not the same as a probability: for example:

    DO .1 <- #1
    DO %50 .1 <- #2
    DO READ OUT .1
    PLEASE GIVE UP

Will output either I or II, each case selected with equal probability. By contrast:

    DO .1 <- #1
    DO .1 <- #2 WHILE NOT ASSIGNING IT
    DO READ OUT .1
    PLEASE GIVE UP

Will output both I and II, because the program enters a superposition of two states, one in which .1 has value #1 and another one in which it has value #2.

Please note that observing the program running may cause collapse of the quantum state function, and therefore result in observable probabilities instead. However, the quantum emulator which comes with CLC-INTERCAL does not do this.

External resources