| Crates.io | quantrs2-symengine-sys |
| lib.rs | quantrs2-symengine-sys |
| version | 0.1.0-rc.1 |
| created_at | 2025-06-17 11:50:32.321175+00 |
| updated_at | 2025-12-27 21:44:13.150381+00 |
| description | Low level bindings to the symengine library (fixed for macOS) |
| homepage | |
| repository | https://github.com/cool-japan/quantrs |
| max_upload_size | |
| id | 1715587 |
| size | 174,077 |
Low-level Rust FFI bindings to the SymEngine C API.
This crate provides comprehensive, safe FFI bindings to SymEngine's C wrapper API, with enhancements for macOS compatibility and modern bindgen versions.
CMapBasicBasic supportCDenseMatrix operationsis_ok(), is_err(), code())You need SymEngine and its dependencies installed on your system.
brew install symengine gmp mpfr
When building, set the following environment variables:
export SYMENGINE_DIR=$(brew --prefix symengine)
export GMP_DIR=$(brew --prefix gmp)
export MPFR_DIR=$(brew --prefix mpfr)
export BINDGEN_EXTRA_CLANG_ARGS="-I$(brew --prefix symengine)/include -I$(brew --prefix gmp)/include -I$(brew --prefix mpfr)/include"
# Ubuntu/Debian
sudo apt-get install libsymengine-dev libgmp-dev libmpfr-dev
# Fedora/RHEL
sudo dnf install symengine-devel gmp-devel mpfr-devel
# Arch Linux
sudo pacman -S symengine gmp mpfr
vcpkg install symengine gmp mpfr
Add this to your Cargo.toml:
[dependencies]
quantrs2-symengine-sys = { version = "0.1.0-beta.3" }
static: Enable static linking to SymEnginesystem-deps: Use pkg-config to find system dependenciesserde: Enable serde serialization support (when available)Example with features:
[dependencies]
quantrs2-symengine-sys = { version = "0.1.0-beta.3", features = ["static", "serde"] }
All functions in this crate are unsafe as they directly interface with C/C++ code. Users must ensure:
check_result()use quantrs2_symengine_sys::*;
use std::os::raw::c_int;
unsafe {
// Create a symbol
let mut x = std::mem::zeroed::<basic_struct>();
symbol_set(&mut x as *mut _, "x\0".as_ptr() as *const i8);
// Create an integer
let mut two = std::mem::zeroed::<basic_struct>();
integer_set_si(&mut two as *mut _, 2);
// Compute x^2 and check for errors
let mut result = std::mem::zeroed::<basic_struct>();
let code = basic_pow(&mut result as *mut _, &x as *const _, &two as *const _);
check_result(code as c_int).expect("Failed to compute power");
}
For a safer, more idiomatic Rust interface, use the quantrs2-symengine crate which builds on these bindings.
This crate provides bindings to the following SymEngine C API groups:
basic_*: Core symbolic operationssymbol_*: Symbol creation and manipulationinteger_*, rational_*, real_double_*, complex_double_*: Numeric typesvecbasic_*: Vector operationsmapbasicbasic_*: Map/dictionary operationsdense_matrix_*: Dense matrix operationssparse_matrix_*: Sparse matrix operations (when available)ntheory_*: Number theory functionsbasic_diff: Differentiationbasic_expand: Expression expansiondense_matrix_jacobian: Jacobian matrix computationThis crate is part of the QuantRS2 quantum computing framework and follows the SciRS2 Policy:
MIT
Contributions are welcome! Please ensure:
cargo testcargo fmtcargo clippysymengine-sys crate authors