Class SingleQubitGate

java.lang.Object
com.quantum4j.core.gates.SingleQubitGate
All Implemented Interfaces:
Gate
Direct Known Subclasses:
RXGate, RYGate, RZGate, StandardGates.HGate, StandardGates.RXGate, StandardGates.RYGate, StandardGates.RZGate, StandardGates.SGate, StandardGates.TGate, StandardGates.U1Gate, StandardGates.U2Gate, StandardGates.U3Gate, StandardGates.XGate, StandardGates.YGate, StandardGates.ZGate

public abstract class SingleQubitGate extends Object implements Gate
Abstract base class for single-qubit gates.

A single-qubit gate is represented by a 2×2 complex matrix. Subclasses provide specific gate matrices (e.g., Hadamard, Pauli X, Y, Z).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Complex[][]
    2x2 unitary matrix representing this gate
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Construct a single-qubit gate with the given 2×2 matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(StateVector state, int targetQubit)
    Apply this single-qubit gate to the specified target qubit in the given state.
    int
    Get the arity (number of qubits) this gate acts upon.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.quantum4j.core.gates.Gate

    name
  • Field Details

    • matrix

      protected final Complex[][] matrix
      2x2 unitary matrix representing this gate
  • Constructor Details

    • SingleQubitGate

      protected SingleQubitGate(Complex[][] matrix)
      Construct a single-qubit gate with the given 2×2 matrix.
      Parameters:
      matrix - a 2×2 complex matrix
      Throws:
      IllegalArgumentException - if the matrix is not 2×2
  • Method Details

    • arity

      public int arity()
      Description copied from interface: Gate
      Get the arity (number of qubits) this gate acts upon.
      Specified by:
      arity in interface Gate
      Returns:
      1 for single-qubit gates, 2 for two-qubit gates, etc.
    • apply

      public void apply(StateVector state, int targetQubit)
      Apply this single-qubit gate to the specified target qubit in the given state.

      This implementation performs sparse matrix-vector multiplication by updating only the amplitude pairs affected by the target qubit.

      Parameters:
      state - the quantum state to modify
      targetQubit - the index of the qubit to apply the gate to (0 = LSB)
      Throws:
      IllegalArgumentException - if targetQubit is out of range