Home Reference Source
``import {BasicMathGate} from 'projectq/src/ops/basics.js'``
public class

# BasicMathGate

#### Extends:

BasicGate → BasicMathGate

#### Direct Subclass:

Base class for all math gates.

It allows efficient emulation by providing a mathematical representation which is given by the concrete gate which derives from this base class. The AddConstant gate, for example, registers a function of the form

#### Example:

``````
return (x+a,)

upon initialization. More generally, the function takes integers as
parameters and returns a tuple / list of outputs, each entry corresponding
to the function input. As an example, consider out-of-place
multiplication, which takes two input registers and adds the result into a
third, i.e., (a,b,c) -> (a,b,c+a*b). The corresponding function then is``````
``````
function multiply(a,b,c)
return (a,b,c+a*b)``````

## Constructor Summary

 Public Constructor public constructor(mathFunc: function)

## Member Summary

 Public Members public mathFunc: *

## Method Summary

 Public Methods public getMathFunction(qubits: Array): function Return the math function which corresponds to the action of this math gate, given the input to the gate (a tuple of quantum registers). public toString(): string

## Inherited Summary

 From class BasicGate public static makeTupleOfQureg(qubits: Qubit | Qubit[] | Qureg | Qureg[]): Qureg[] Convert quantum input of "gate | quantum input" to internal formatting. public public copy(): BasicGate public equal(other: BasicGate | Object): boolean public generateCommand(qubits: *): Command Helper function to generate a command consisting of the gate and the qubits being acted upon. public public public inspect(): string public or(qubits: *) Operator| overload which enables the syntax Gate | qubits. public toString()

## Public Constructors

### publicconstructor(mathFunc: function) source

#### Override:

BasicGate#constructor

#### Params:

 Name Type Attribute Description mathFunc function Function which takes as many int values as input, as the gate takes registers. For each of these values, it then returns the output (i.e., it returns a list/tuple of output values).

#### Example:

``````
return (a,a+b)

If the gate acts on, e.g., fixed point numbers, the number of bits per
register is also required in order to describe the action of such a
mathematical gate. For this reason, there is``````
``````
BasicMathGate.get_math_function(qubits)

which can be overwritten by the gate deriving from BasicMathGate.``````
``````
function get_math_function(self, qubits)
n = len(qubits[0])
scal = 2.**n
function math_fun(a)
return (int(scal * (math.sin(math.pi * a / scal))),)
return math_fun``````

## Public Methods

### publicgetMathFunction(qubits: Array<Qureg>): function source

Return the math function which corresponds to the action of this math gate, given the input to the gate (a tuple of quantum registers).

#### Params:

 Name Type Attribute Description qubits Array Qubits to which the math gate is being applied.

#### Return:

 function javascript function describing the action of this gate. (See BasicMathGate.constructor for an example).

### publictoString(): string source

#### Override:

BasicGate#toString