commutator-rs
A Rust library for commutator operations.
Overview
- Commutator operations:
[A, B] = AB - BA - Commutator terms for algebraic expressions
- Formal indeterminates for symbolic computation
- Expression trees for nested commutators
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Commutator Operations
use *;
// Create formal indeterminates
let x = new;
let y = new;
// Compute commutator [x, y] using the trait
let result = x.commutator;
println!;
// For simple types, commutator of identical elements is zero
let zero_result = 5.commutator;
println!; // Should be 0
Using the comm! Macro
For convenient syntax, use the comm! macro instead of calling .commutator() directly:
use ;
let x = Atom ;
let y = Atom ;
// These are equivalent:
let result1 = x.commutator;
let result2 = comm!;
// Nested commutators are easy to read:
let a = from;
let b = from;
let c = from;
let nested = comm!; // [[a, b], c]
Working with Commutator Terms
use *;
use ENotation;
// Create commutator terms from generators
let e1 = new;
let e2 = new;
let e3 = new;
// Build a simple commutator term
let term1 = Atom ;
let term2 = Atom ;
// Create nested commutator: [[e1, e2], e3]
let inner_comm = Expression ;
let term3 = Atom ;
let outer_comm = Expression ;
println!;
Creating Complex Expressions
use *;
use HashMap;
// Create a more complex example with coefficients
let mut expression = new;
// Create formal indeterminates
let x = new;
let y = new;
let z = new;
// Compute various commutators
let xy_comm = x.commutator;
let xz_comm = x.commutator;
let yz_comm = y.commutator;
println!;
println!;
println!;
// These can be used in further algebraic computations
let nested = xy_comm.commutator;
println!;
Integration with Lyndon Words
use *;
use *;
// Create commutator terms using generators from Lyndon words
let generators = vec!;
// Try to create a Lyndon word
if let Ok = try_from
Custom Types with Commutators
use Commutator;
use ;
// Define a custom matrix-like type
// Usage
let m1 = new;
let m2 = new;
let comm = m1.commutator;
println!;
Key Types
Commutator: Trait defining the commutator operationCommutatorTerm<T, U>: Represents either atomic terms or nested commutator expressionsFormalIndeterminate<T, U>: Abstract algebraic elements for symbolic computationcomm!: Macro for commutator syntax