Skip to main content

SpinHalfOperator

Base class: Operator

Base class for spin-1/2 symbolic operators.

Operators

CNOT(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the CNOT (controlled-NOT) gate, taking two individual site indices.

Parameters

  • site0: The control qubit site index.
  • site1: The target qubit site index.

Example

var cnot1 = CNOT(0, 1)

DualUnitary(real J, integer i, integer j) -> SpinHalfOperator

Returns a spin-1/2 dual unitary operator: exp(i(π4X(i)X(j)+π4Y(i)Y(j)+JzZ(i)Z(j)))\exp(i(\frac{\pi}{4} X(i) X(j) + \frac{\pi}{4} Y(i) Y(j) + J_z Z(i) Z(j))) where i,ji, j are the site indices.

Parameters

  • J: The Jz constant parameter.
  • i: Site index i.
  • j: Site index j.

Example

var dual_u = DualUnitary(0.25, 0, 1) // Dual unitary with Jz=0.25

Flip(integer site) -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that flips the spin at a single site.

Parameters

  • site: The site index where the spin is flipped.

Flip(const List<integer> sites) -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that flips spins at specified sites.

Parameters

  • sites: Vector of site indices where spins are flipped.

FlipAll() -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that flips all spins.

Floquet(const List<real> Js, integer i, integer j) -> SpinHalfOperator

Returns a spin-1/2 Floquet(Jx,Jy,Jz)=exp(i(JxX(i)+JyY(i)+JzZ(i))Z(j))(J_x, J_y, J_z) = \exp(i(J_x X(i) + J_y Y(i) + J_z Z(i)) Z(j)) where i,ji, j are the site indices.

Parameters

  • Js: Vector of exactly three parameters [Jx, Jy, Jz].
  • i: Site index i.
  • j: Site index j.

Example

var flqt = Floquet([0.2, 0.3, 0.8], 1, 2) // Floquet operator

Hgate(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the Hadamard gate.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var h0 = Hgate(0)

Permute(const List<integer> permutation, const List<integer> sites) -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that permutes spins according to a specified permutation.

Parameters

  • permutation: Vector defining the permutation of spins (destination indices).
  • sites: Vector of site indices where the permutation is applied.

Phase(real phi) -> SpinHalfOperator

Returns a global phase spin-1/2 operator P(ϕ)=eiϕP(\phi) = e^{-i\phi}.

Parameters

  • phi: The phase angle.

Example

var ps = Phase(3.14159) // π phase

PhaseShift(real phi, integer site) -> SpinHalfOperator

Returns a spin-1/2 PhaseShift(ϕ)=exp(iϕ)(\phi) = \exp(i\phi) on the 1|1\rangle state.

Parameters

  • phi: The rotation angle.
  • site: The site index where the operator acts.

Example

var ps_half = PhaseShift(1.5708, 0)

Proj0(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the projector 00|0\rangle\langle 0|.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var p0_op = Proj0(0)

Proj1(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the projector 11|1\rangle\langle 1|.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var p1_op = Proj1(1)

Reflect() -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that reflects all spins about the center.

RotEuler(real phi, real theta, real omega, integer site) -> SpinHalfOperator

Returns a general spin-1/2 rotation operator RotEuler(ϕ,θ,ω)=RZ(ω)RX(θ)RZ(ϕ)=exp(iωZ/2)exp(iθX/2)exp(iϕZ/2)(\phi,\theta,\omega) = RZ(\omega)RX(\theta)RZ(\phi) = \exp(-i \omega Z/2) \exp(-i \theta X/2) \exp(-i \phi Z/2).

Parameters

  • phi: The first rotation angle.
  • theta: The second rotation angle.
  • omega: The third rotation angle.
  • site: The site index where the operator acts.

Example

var rot0 = RotEuler(1.57, 0.78, 3.14, 0) // General rotation on site 0

RotX(real phi, integer site) -> SpinHalfOperator

Returns a spin-1/2 RotX(ϕ)=exp(iϕX/2)(\phi) = \exp(-i\phi X/2) rotation operator around the X-axis.

Parameters

  • phi: The rotation angle.
  • site: The site index where the operator acts.

Example

var rx_half = RotX(1.5708, 0) // π/2 rotation on site 0

RotY(real phi, integer site) -> SpinHalfOperator

Returns a spin-1/2 RotY(ϕ)=exp(iϕY/2)(\phi) = \exp(-i\phi Y/2) rotation operator around the Y-axis.

Parameters

  • phi: The rotation angle.
  • site: The site index where the operator acts.

Example

var ry_quarter = RotY(0.7854, 1) // π/4 rotation on site 1

RotZ(real phi, integer site) -> SpinHalfOperator

Returns a spin-1/2 RotZ(ϕ)=exp(iϕZ/2)(\phi) = \exp(-i\phi Z/2) rotation operator around the Z-axis.

Parameters

  • phi: The rotation angle.
  • site: The site index where the operator acts.

Example

var rz_full = RotZ(6.28318, 2) // 2π rotation on site 2

SWAP(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the SWAP gate, taking two individual site indices.

Parameters

  • site0: The first site index.
  • site1: The second site index.

Example

var swap1 = SWAP(0, 1)

Sgate(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the S gate.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var s0 = Sgate(0)

Sminus(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for Spin-minus operator.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var sm1 = Sminus(1)

Splus(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for Spin-plus operator.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var sp0 = Splus(0)

Tgate(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for the T gate.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var t0 = Tgate(0)

Translate(integer shift) -> SpinHalfOperator

Creates a spin-1/2 OperatorPermute that translates spins by a specified shift.

Parameters

  • shift: Number of sites by which the spins are shifted (default: 1).

UnitaryXYZ(const List<real> Js, integer i, integer j) -> SpinHalfOperator

Returns a spin-1/2 UnitaryXYZ(Jx,Jy,Jz)(J_x, J_y, J_z) operator: exp(i(JxX(i)X(j)+JyY(i)Y(j)+JzZ(i)Z(j)))\exp(i(J_x X(i) X(j) + J_y Y(i) Y(j) + J_z Z(i) Z(j))) where i,ji, j are the site indices.

Parameters

  • Js: Vector of exactly three parameters: [Jx, Jy, Jz].
  • i: Site index i.
  • j: Site index j.

Example

var xyz01 = UnitaryXYZ([0.5, 1.0, 1.5], 0, 1) // coupling between sites 0 and 1

X(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for Pauli-X operator.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var px0 = X(0)

XX(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for XiXjX_i \cdot X_j operator, taking two individual site indices.

Parameters

  • site0: The first site index (ii).
  • site1: The second site index (jj).

Example

var pxx1 = XX(1, 2)

XXPYY(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for XiXj+YiYjX_i \cdot X_j + Y_i \cdot Y_j operator, taking two individual site indices.

Parameters

  • site0: The first site index.
  • site1: The second site index.

Example

var xxpyy1 = XXPYY(0, 1)

Y(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for Pauli-Y operator.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var py1 = Y(1)

YY(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for YiYjY_i \cdot Y_j operator, taking two individual site indices.

Parameters

  • site0: The first site index.
  • site1: The second site index.

Example

var pyy1 = YY(0, 1)

Z(integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for Pauli-Z operator.

Parameters

  • site: The site index where the operator acts (exactly 1 site required).

Example

var pz2 = Z(2)

ZN(const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for isitesZi \sum_{i \in \text{sites}} Z_i operator.

Parameters

  • sites: Vector of site indices where the operator acts (minimum 1 site).

Example

var zn_s = ZN([0]) // Single site: use brackets (vector format)
var zn_m = ZN([0, 1, 2, 3])
// ZN(0) would be INVALID - missing brackets

ZZ(integer site0, integer site1) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for ZiZjZ_i \cdot Z_j operator, taking two individual site indices.

Parameters

  • site0: The first site index.
  • site1: The second site index.

Example

var pzz1 = ZZ(0, 2)

ZZNN(const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for isitesZiZi+1 \sum_{i \in \text{sites}} Z_i \otimes Z_{i+1} operator.

Parameters

  • sites: Vector of site indices where the operator acts (minimum 2 sites).

Example

var zznn_s = ZZNN([0, 1]) // Minimum sites: use brackets (vector format)
var zznn_m = ZZNN([0, 1, 2, 3])
// ZZNN(0, 1) would be INVALID - missing brackets

ZZNNN(const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorNamed for isitesZiZi+2 \sum_{i \in \text{sites}} Z_i \otimes Z_{i+2} operator.

Parameters

  • sites: Vector of site indices where the operator acts (minimum 3 sites).

Example

var zznnn_s = ZZNNN([0, 1, 2]) // use brackets (vector format)
var zznnn_m = ZZNNN([0, 1, 2, 3, 4])
// ZZNNN(0, 1, 2) would be INVALID - missing brackets

operator_dense(const RealMatrix matrix, integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorDense parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • site: The site index where the operator acts.

operator_dense(const RealMatrix matrix, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorDense parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • sites: Vector of site indices where the operator acts.

operator_dense(const ComplexMatrix matrix, integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorDense parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • site: The site index where the operator acts.

operator_dense(const ComplexMatrix matrix, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorDense parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const ComplexMatrix diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const RealMatrix diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const List<complex> diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const List<real> diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const List<real> diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const List<integer> diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_diagonal(const List<integer> diagonal, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 diagonal operator with specified diagonal elements.

Parameters

  • diagonal: Vector containing the operator diagonal elements.
  • sites: Vector of site indices where the operator acts.

operator_generic(const OperatorGenericFunction<ComplexMatrix, IntegerArray> function, const List<integer> sites) -> SpinHalfOperator

Creates a spin-1/2 OperatorGeneric from a string representation.

Parameters

  • function: A function taking a vector and an array of indices.
  • sites: Vector of site indices where the operator acts.

operator_generic(const OperatorGenericFunction<RealMatrix, IntegerArray> function, const List<integer> sites, as_real type_tag) -> SpinHalfOperator

Creates a spin-1/2 OperatorGeneric from a string representation.

Parameters

  • function: A function taking a vector and an array of indices.
  • sites: Vector of site indices where the operator acts.
  • type_tag: A global constant tagging the object type.

operator_generic(const OperatorGenericFunction<ComplexMatrix, IntegerArray> function, const List<integer> sites, as_complex type_tag) -> SpinHalfOperator

Creates a spin-1/2 OperatorGeneric from a string representation.

Parameters

  • function: A function taking a vector and an array of indices.
  • sites: Vector of site indices where the operator acts.
  • type_tag: A global constant tagging the object type.

operator_sparse(const RealSparseMatrix matrix, integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorSparse parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • site: The site index where the operator acts.

operator_sparse(const RealSparseMatrix matrix, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorSparse parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • sites: Vector of site indices where the operator acts.

operator_sparse(const ComplexSparseMatrix matrix, integer site) -> SpinHalfOperator

Returns a spin-1/2 OperatorSparse parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • site: The site index where the operator acts.

operator_sparse(const ComplexSparseMatrix matrix, const List<integer> sites) -> SpinHalfOperator

Returns a spin-1/2 OperatorSparse parametrized by the given matrix.

Parameters

  • matrix: The matrix parametrizing the operator.
  • sites: Vector of site indices where the operator acts.

pauli_string(const string word, const List<integer> sites) -> SpinHalfOperator

Creates a spin-1/2 OperatorPauliString from a string representation.

Parameters

  • word: String representation of the Pauli string (e.g., "XYZ").
  • sites: Vector of site indices where the operator acts.

Example

var pauli0 = pauli_string("XYZX", [1, 6, 2, 3])

Members

NameDescription
nameReturns the symbolic name of a spin-1/2 operator.
parametersReturns the sparse real matrix payload of a spin-1/2 operator.
sitesReturns the sites of a spin-1/2 operator in definition order.