Matrix construction and access
Construct matrices from ordered rows or from identity, zero, and diagonal families. Shape and entry access preserve row-major ordering.
Constructors#
matrix#
api::Session method
pub fn matrix<RowsIterator, RowIterator>(
&self,
rows: RowsIterator,
) -> Result<Matrix, ApiError>
where
RowsIterator: IntoIterator<Item = RowIterator>,
RowIterator: IntoIterator<Item = Expression>,Build a matrix from ordered rows. Direct Python construction and the facade
module function use the shared default context. The raw wasm-bindgen
compatibility layer retains (rows, columns, flat_entries); new JavaScript
code should use the nested facade form.
matrix_identity#
api::Session method
pub fn matrix_identity(&self, size: usize) -> Result<Matrix, ApiError>The identity; size 0 raises.
matrix_zero#
api::Session method
pub fn matrix_zero(
&self,
rows: usize,
columns: usize,
) -> Result<Matrix, ApiError>The zero matrix.
matrix_diagonal#
api::Session method
pub fn matrix_diagonal<'a, IteratorType>(
&self,
entries: IteratorType,
) -> Result<Matrix, ApiError>
where
IteratorType: IntoIterator<Item = &'a Expression>,Square matrix with the given main diagonal and zeros elsewhere; the empty list raises.
Shape and access#
rows#
api::Matrix method
pub fn rows(&self) -> usizecolumns#
api::Matrix method
pub fn columns(&self) -> usizeentry#
api::Matrix method
pub fn entry(
&self,
row: usize,
column: usize,
) -> Result<Expression, ApiError>Element access. Notes: Python uses indexing m[row, column] instead.
Example#
Build matrices from rows or from a structured constructor.
use symi::api::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let session = Session::new();
let x = session.symbol("x");
let matrix = session.matrix([
[session.integer(1), x.clone()],
[x.clone(), session.integer(1)],
])?;
println!("{} x {}", matrix.rows()?, matrix.columns()?);
println!("{}", matrix.entry(0, 1)?);
Ok(())
}Additional API#
diagonal_matrix#
api::Session method
pub fn diagonal_matrix(
&self,
subject: &Matrix,
) -> Result<AssumptionProposition, ApiError>Construct a diagonal-matrix proposition.
identity_matrix#
api::Session method
pub fn identity_matrix(
&self,
subject: &Matrix,
) -> Result<AssumptionProposition, ApiError>Construct an identity-matrix proposition.
zero_matrix#
api::Session method
pub fn zero_matrix(
&self,
subject: &Matrix,
) -> Result<AssumptionProposition, ApiError>Construct a zero-matrix proposition.