Class ThreeQubitGate

java.lang.Object
com.quantum4j.core.gates.ThreeQubitGate
All Implemented Interfaces:
Gate
Direct Known Subclasses:
CCXGate, StandardGates.CCXGate

public abstract class ThreeQubitGate extends Object implements Gate
Abstract base class for three-qubit gates. A three-qubit gate is represented by an 8×8 complex matrix in the local basis: |q0 q1 q2⟩ = |000⟩, |001⟩, ..., |111⟩ where q0, q1, q2 are exactly the three qubit indices passed to apply(StateVector, int, int, int) in that order. This avoids internal reordering and preserves correct semantics for asymmetric gates like CCX (Toffoli) where the position of controls and target matters.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Complex[][]
    8×8 unitary matrix in local ordering |q0 q1 q2⟩.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ThreeQubitGate(Complex[][] matrix)
    Construct a three-qubit gate with the given 8×8 matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(StateVector state, int q0, int q1, int q2)
    Apply this gate to qubits (q0, q1, q2) in that logical order.
    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
      8×8 unitary matrix in local ordering |q0 q1 q2⟩.
  • Constructor Details

    • ThreeQubitGate

      protected ThreeQubitGate(Complex[][] matrix)
      Construct a three-qubit gate with the given 8×8 matrix.
      Parameters:
      matrix - an 8×8 complex matrix
  • 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 q0, int q1, int q2)
      Apply this gate to qubits (q0, q1, q2) in that logical order. Local basis index mapping: local index k = (b0 << 2) | (b1 << 1) | b2 where b0, b1, b2 are the bits of (q0, q1, q2) respectively.