LanQ – a quantum imperative programming language

Index

Statements

Variable declaration

Expressions

Operators

Methods

Quantum Operators

Statement block

Declaration

{ block-forming statements }

Description

Groups given block-forming statements.

Statement fork

Declaration

fork methodName([p0 [, p1 [, ...]]]);

Description

Starts a new process. The process execution is started from given method methodName. Any nonduplicable resources passed as arguments to the newly started process become unavailable in the original process.

Statement if

Declaration

if (expr) statement1 [else statement2]

Description

If given expr evaluates to true, executes the statement1, else executes the statement2.

Statement return

Declaration

return;
return expr;

Description

Finishes execution of a method and eventually returns given expr as a return value of the method.

Statement send

Declaration

send(channelEndName, value);

Description

Sends given value value over a channel whose one end is available to the process as channelEndName. Any nonduplicable resource passed as the sent value becomes unavailable in the sending process. This is a blocking operation.

Statement skip

Declaration

;

Description

Performs no operation.

Statement while

Declaration

while (expr) statement

Description

While expr evaluates to true, executes given statement.

Variable declaration - channel with ends declaration

Declaration

channel[T] id0 withends [id1, id2];

Description

Declares a new channel variable id0 of type channel[T] and variables id1 and id2 of type channelEnd[T] which denote individual ends of the channel.

Variable declaration - compound quantum system

Declaration

id aliasfor [id0 [, id1 [, ...]]];

Description

Declares a new quantum variable id0 which acts as a compound quantum system whose components are quantum systems id1, id2, ...

Variable declaration - default

Declaration

T id0 [, id1 [, ...]];

Description

Declares new variables id0, id1, ... of type T.

Expression allocation

Declaration

new T()

Description

Allocates new quantum system (if T is a quantum type) or a new channel (if T is a channel type).

Return value

The newly allocated resource.

Expression assignment

Declaration

x = expr

Description

Assigns the result of evaluation of given expr to variable x.

Return value

The result of evaluation of given expr.

Expression constant

Declaration

c

Description

Evaluates to the value of the constant c.

Return value

The value of the constant c.

Expression measurement

Declaration

measure(basis, q0 [, q1 [, ...]])

Description

Measures given quantum systems q0, q1, ... in given measurement basis basis. Possible bases are StdBasis, DualBasis and BellBasis.

Return value

The index of the first eigenvalue which is returned as the measurement result.

Expression method call

Declaration

methodName([p0 [, p1 [, ...]]])

Description

Calls the method methodName with given arguments.

Return value

The return value of the called method.

Expression recv

Declaration

recv(channelEndName);

Description

Receives a value from given channel end. This is a blocking operation.

Return value

The received value.

Operator !=

Syntax

p0 != p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Returns true iff the numbers are nonequal.

Operator &&

Syntax

p0 && p1

Arguments

NameTypeDescription
p0boolFirst operand
p1boolSecond operand

Description

Returns true iff both operands are true.

Operator ||

Syntax

p0 || p1

Arguments

NameTypeDescription
p0boolFirst operand
p1boolSecond operand

Description

Returns true iff either operand is true.

Operator +

Syntax

p0 + p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Adds two numbers and returns result.

Operator -

Syntax

p0 - p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Subtracts second number from the first and returns result.

Operator *

Syntax

p0 * p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Multiplies two numbers and returns result.

Operator /

Syntax

p0 / p1

Arguments

NameTypeDescription
p0intDividend
p1intDivisor

Description

Divides the first number by the second and returns the result.

Operator %

Syntax

p0 % p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Divides the first number by the second number and returns the remainder.

Operator .

Syntax

p0 . p1

Arguments

NameTypeDescription
p0stringFirst string
p1stringSecond string

or
NameTypeDescription
p0stringFirst string
p1intSecond integer

or
NameTypeDescription
p0stringFirst integer
p1intSecond string

Description

Concatenates the string representation of the arguments and returns the result string.

Operator ==

Syntax

p0 == p1

Arguments

NameTypeDescription
p0intFirst number
p1intSecond number

Description

Returns true iff the numbers are equal.

Quantum operator CNot

Syntax

CNot( p0 , p1 )

Arguments

NameTypeDescription
p0qbitFirst qubit
p1qbitSecond qubit

Description

Applies a CNOT operator to given qubits. Qubit p0 acts as a control qubit, qubit p1 acts as a target qubit.

Quantum operator Had

Syntax

Had( p0 )

Arguments

NameTypeDescription
p0qbitQubit to apply the operator on

Description

Applies Hadamard operator to given qubit.

Quantum operator Sigma_x

Syntax

Sigma_x( p0 )

Arguments

NameTypeDescription
p0qbitQubit to apply the operator on

Description

Applies Pauli sigma_x operator to given qubit.

Quantum operator Sigma_y

Syntax

Sigma_y( p0 )

Arguments

NameTypeDescription
p0qbitQubit to apply the operator on

Description

Applies Pauli sigma_y operator to given qubit.

Quantum operator Sigma_z

Syntax

Sigma_z( p0 )

Arguments

NameTypeDescription
p0qbitQubit to apply the operator on

Description

Applies Pauli sigma_z operator to given qubit.

Method dump_q

Syntax

dump_q( p0 )

Arguments

NameTypeDescription
p0q-0-itQuantum system of any dimension

Description

Displays state (the density matrix) of given quantum system.

Method print

Syntax

print( p0 )

Arguments

NameTypeDescription
p0intInteger to print

or
NameTypeDescription
p0stringString to print

Description

Prints given integer or string to standard output.