cpx-mat2by2

Crates.iocpx-mat2by2
lib.rscpx-mat2by2
version0.1.3
created_at2025-04-24 01:30:24.604218+00
updated_at2025-06-19 07:43:22.254867+00
descriptionTo power the rust-quantum project, this library provides a robust AltMat type for a single qubit, specifically optimized for the intensive complex number multiplications required for quantum gate applications and tensor product operations.
homepage
repositoryhttps://github.com/enjuichang123/cpx-mat2by2.git
max_upload_size
id1646515
size93,738
En-Jui Chang (enjuichang123)

documentation

https://docs.rs/cpx-mat2by2/latest/cpx-mat2by2/index.html

README

cpx-mat2by2

cpx-mat2by2 is a Rust library for representing separable quantum states and structured 2×2 complex operators in quantum computation.
It is designed to integrate seamlessly with the cpx-coords crate, which provides coordinate-system-aware complex number types Cpx<T>, where T is typically f32 or f64.

This crate emphasizes canonical normalization of quantum states and operators, making equality checks robust, particularly useful when constructing entangled states or modeling non-trivial k-local operations.


Design Principles

  • Global phase is ignored in separable states and 2×2 matrices: canonicalization ensures the unique representation, which is only restored when coherent superpositions are explicitly handled.

  • Normalization is enforced to ensure:

    • Pure states have unit norm and fixed global phase (c₀ ∈ ℝ₊)
    • Operators follow structured forms (e.g., unit determinant for rank-2 matrices)
  • Matrix classification:

    • Rank-0: Zero matrix
    • Rank-1: Further subdivided into:
      • Projector: |ψ⟩⟨ψ|
      • Nilpotent: |ψ⟩⟨ψ⊥| or |ψ⊥⟩⟨ψ|
      • General outer product: |ket⟩⟨bra|
    • Rank-2: Full-rank 2×2 matrices, restricted to unit determinant and classified by Hermiticity
  • Pauli-based representations (complex quaternion form) are used to encode all 2×2 operators, supporting both real (Hermitian) and complex coefficients.

  • Multi-qubit structures use BTreeMap<usize, _> (not HashMap) to ensure deterministic key ordering.
    This facilitates consistent hashing and composability for high-level quantum operations in future crates.

This crate is part of the broader rust-quantum project, focused on efficient numerical quantum computation.

Usage

Installation

Add cpx-mat2by2 as a dependency to your Cargo.toml file:

[dependencies]
cpx-mat2by2 = "0.1.3" # Replace with the latest version

License

This project is licensed under either of

at your option.

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you shall be licensed as above, without any additional terms or conditions.

Commit count: 0

cargo fmt