SymbolicMatrix

Struct SymbolicMatrix 

Source
pub struct SymbolicMatrix { /* private fields */ }
Expand description

A symbolic matrix where each element is an Expression.

This is useful for representing parameterized quantum gates, symbolic Hamiltonians, and other matrix expressions.

Implementations§

Source§

impl SymbolicMatrix

Source

pub fn new(elements: Vec<Vec<Expression>>) -> SymEngineResult<Self>

Create a new symbolic matrix from a 2D array of expressions.

§Errors

Returns error if the input is empty

Source

pub fn from_flat( elements: Vec<Expression>, rows: usize, cols: usize, ) -> SymEngineResult<Self>

Create a matrix from a flat vector with specified dimensions.

§Errors

Returns error if the dimensions don’t match the vector length

Source

pub fn zeros(rows: usize, cols: usize) -> Self

Create a zero matrix.

Source

pub fn identity(n: usize) -> Self

Create an identity matrix.

Source

pub fn diagonal(diag: Vec<Expression>) -> Self

Create a diagonal matrix from a vector of diagonal elements.

Source

pub fn from_array(arr: &Array2<f64>) -> Self

Create a matrix from a numeric Array2.

Source

pub fn from_complex_array(arr: &Array2<Complex64>) -> Self

Create a matrix from a complex Array2.

Source

pub const fn nrows(&self) -> usize

Get the number of rows.

Source

pub const fn ncols(&self) -> usize

Get the number of columns.

Source

pub const fn shape(&self) -> (usize, usize)

Get the dimensions as (rows, cols).

Source

pub const fn is_square(&self) -> bool

Check if the matrix is square.

Source

pub fn get(&self, i: usize, j: usize) -> &Expression

Get element at (i, j).

§Panics

Panics if indices are out of bounds.

Source

pub fn get_mut(&mut self, i: usize, j: usize) -> &mut Expression

Get mutable reference to element at (i, j).

§Panics

Panics if indices are out of bounds.

Source

pub fn set(&mut self, i: usize, j: usize, value: Expression)

Set element at (i, j).

§Panics

Panics if indices are out of bounds.

Source

pub fn row(&self, i: usize) -> Vec<Expression>

Get a row as a vector of expressions.

Source

pub fn col(&self, j: usize) -> Vec<Expression>

Get a column as a vector of expressions.

Source

pub fn transpose(&self) -> Self

Matrix transpose.

Source

pub fn conjugate(&self) -> Self

Complex conjugate of all elements.

Source

pub fn dagger(&self) -> Self

Hermitian conjugate (conjugate transpose).

Source

pub fn add(&self, other: &Self) -> SymEngineResult<Self>

Matrix addition.

§Errors

Returns error if dimensions don’t match.

Source

pub fn sub(&self, other: &Self) -> SymEngineResult<Self>

Matrix subtraction.

§Errors

Returns error if dimensions don’t match.

Source

pub fn matmul(&self, other: &Self) -> SymEngineResult<Self>

Matrix multiplication.

§Errors

Returns error if inner dimensions don’t match.

Source

pub fn scale(&self, scalar: &Expression) -> Self

Scalar multiplication.

Source

pub fn kron(&self, other: &Self) -> Self

Kronecker (tensor) product.

Source

pub fn trace(&self) -> SymEngineResult<Expression>

Matrix trace (sum of diagonal elements).

§Errors

Returns error if matrix is not square.

Source

pub fn commutator(&self, other: &Self) -> SymEngineResult<Self>

Commutator [A, B] = AB - BA.

§Errors

Returns error if dimensions don’t match or matrices are not square.

Source

pub fn anticommutator(&self, other: &Self) -> SymEngineResult<Self>

Anticommutator {A, B} = AB + BA.

§Errors

Returns error if dimensions don’t match.

Source

pub fn simplify(&self) -> Self

Simplify all matrix elements.

Source

pub fn expand(&self) -> Self

Expand all matrix elements.

Source

pub fn eval( &self, values: &HashMap<String, f64>, ) -> SymEngineResult<Array2<f64>>

Evaluate all matrix elements with given variable values.

§Errors

Returns error if any element evaluation fails.

Source

pub fn substitute(&self, var: &Expression, value: &Expression) -> Self

Substitute a variable with an expression in all elements.

Source

pub fn diff(&self, var: &Expression) -> Self

Compute the derivative of all elements with respect to a variable.

Trait Implementations§

Source§

impl Clone for SymbolicMatrix

Source§

fn clone(&self) -> SymbolicMatrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolicMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SymbolicMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<(usize, usize)> for SymbolicMatrix

Source§

type Output = Expression

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for SymbolicMatrix

Source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V