[][src]Struct quest_rs::ComplexMatrix4

pub struct ComplexMatrix4 {
    pub real: [[f64; 4]; 4],
    pub imag: [[f64; 4]; 4],
}

Represents a 4x4 matrix of complex numbers.

Examples

use quest_rs::{Complex, ComplexMatrix4};
 
let sqrt_swap = ComplexMatrix4::new([
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 0.5, 0.5, 0.0],
    [0.0, 0.5, 0.5, 0.0],
    [0.0, 0.0, 0.0, 1.0],
], [
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.5, -0.5, 0.0],
    [0.0, -0.5, 0.5, 0.0],
    [0.0, 0.0, 0.0, 0.0],
]);
assert_eq!(sqrt_swap.real, [
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 0.5, 0.5, 0.0],
    [0.0, 0.5, 0.5, 0.0],
    [0.0, 0.0, 0.0, 1.0],
]);
assert_eq!(sqrt_swap.imag, [
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.5, -0.5, 0.0],
    [0.0, -0.5, 0.5, 0.0],
    [0.0, 0.0, 0.0, 0.0],
]);
 
let sqrt_swap_compact = ComplexMatrix4::compact([
    [Complex::real(1.0), Complex::zero(), Complex::zero(), Complex::zero()],
    [Complex::zero(), Complex::new(0.5, 0.5), Complex::new(0.5, -0.5), Complex::zero()],
    [Complex::zero(), Complex::new(0.5, -0.5), Complex::new(0.5, 0.5), Complex::zero()],
    [Complex::zero(), Complex::zero(), Complex::zero(), Complex::real(1.0)],
]);
assert_eq!(sqrt_swap.real, sqrt_swap_compact.real);
assert_eq!(sqrt_swap.imag, sqrt_swap_compact.imag);
 
let controlled_z = ComplexMatrix4::real([
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0, 0.0],
    [0.0, 0.0, 1.0, 0.0],
    [0.0, 0.0, 0.0, -1.0],
]);
assert_eq!(controlled_z.real, [
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0, 0.0],
    [0.0, 0.0, 1.0, 0.0],
    [0.0, 0.0, 0.0, -1.0],
]);
assert_eq!(controlled_z.imag, [
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
]);
 
let imaginary_cnot = ComplexMatrix4::imag([
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 1.0],
    [0.0, 0.0, 1.0, 0.0],
]);
assert_eq!(imaginary_cnot.real, [
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
]);
assert_eq!(imaginary_cnot.imag, [
    [1.0, 0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 1.0],
    [0.0, 0.0, 1.0, 0.0],
]);

Fields

real: [[f64; 4]; 4]imag: [[f64; 4]; 4]

Methods

impl ComplexMatrix4[src]

pub fn new(real: [[QReal; 4]; 4], imag: [[QReal; 4]; 4]) -> Self[src]

pub fn compact(values: [[Complex; 4]; 4]) -> Self[src]

pub fn real(real: [[QReal; 4]; 4]) -> Self[src]

pub fn imag(imag: [[QReal; 4]; 4]) -> Self[src]

Trait Implementations

impl Clone for ComplexMatrix4[src]

impl Copy for ComplexMatrix4[src]

impl Debug for ComplexMatrix4[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.