Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Nonanti/mathcore/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through adding MathCore to a Rust project and running your first symbolic math operations — arithmetic evaluation, symbolic differentiation, and equation solving — using real code straight from the library. By the end you will have a working program that demonstrates MathCore’s core capabilities.
1

Add MathCore to your project

Inside your project’s root directory, run:
cargo add mathcore
Or add the dependency manually to Cargo.toml:
[dependencies]
mathcore = "0.3.1"
The default feature set (std, parallel, fft) is appropriate for most desktop and server applications. See the Installation guide if you need a trimmed-down or no_std build.
2

Import MathCore

At the top of your Rust source file, bring the main struct and the prelude into scope:
use mathcore::prelude::*;
use mathcore::MathCore;
The prelude module re-exports commonly needed types (String, Vec, HashMap, fmt, and numeric traits) in a way that works in both std and no_std environments.
3

Evaluate a basic arithmetic expression

Create a MathCore instance and call calculate to evaluate an expression string. Operator precedence is handled automatically:
use mathcore::MathCore;

fn main() {
    let math = MathCore::new();

    // basic arithmetic with correct precedence
    let result = math.calculate("2 + 3 * 4").unwrap();
    println!("2 + 3 * 4 = {}", result);  // 14

    // parentheses override precedence
    let result = math.calculate("(2 + 3) * 4").unwrap();
    println!("(2 + 3) * 4 = {}", result);  // 20

    // exponentiation
    let result = math.calculate("2^8").unwrap();
    println!("2^8 = {}", result);  // 256
}
calculate returns Result<f64, MathError>, so .unwrap() is fine for quick scripts — use proper error handling in production code.
4

Differentiate an expression symbolically

MathCore::differentiate is a static method that parses an expression string and returns its derivative as a symbolic Expr, which implements Display:
use mathcore::MathCore;

fn main() {
    // polynomial
    let deriv = MathCore::differentiate("x^2 + 2*x + 1", "x").unwrap();
    println!("d/dx(x^2 + 2*x + 1) = {}", deriv);  // 2*x + 2

    // product rule
    let deriv = MathCore::differentiate("x * sin(x)", "x").unwrap();
    println!("d/dx(x * sin(x)) = {}", deriv);

    // chain rule
    let deriv = MathCore::differentiate("e^x", "x").unwrap();
    println!("d/dx(e^x) = {}", deriv);

    // cubic polynomial
    let deriv = MathCore::differentiate("x^3 + 2*x^2 + x + 1", "x").unwrap();
    println!("d/dx(x^3 + 2*x^2 + x + 1) = {}", deriv);
}
The second argument to differentiate is the variable to differentiate with respect to. You can use any single-character or multi-character symbol that appears in the expression.
5

Solve an equation for its roots

Pass an expression (implicitly set equal to zero) and the target variable to MathCore::solve. It returns a Vec<Expr> containing all roots:
use mathcore::MathCore;

fn main() {
    // difference of squares — two real roots
    let roots = MathCore::solve("x^2 - 4", "x").unwrap();
    println!("roots of x^2 - 4 = 0: {:?}", roots);  // [2, -2]

    // quadratic — two real roots
    let roots = MathCore::solve("x^2 + x - 6", "x").unwrap();
    println!("roots of x^2 + x - 6 = 0: {:?}", roots);  // [2, -3]

    // linear equation
    let roots = MathCore::solve("2*x - 10", "x").unwrap();
    println!("roots of 2*x - 10 = 0: {:?}", roots);  // [5]
}
MathCore::solve supports linear, quadratic, and select higher-degree equations. For systems of linear equations, see the Matrix Operations guide.

Putting it all together

Here is the complete main.rs combining all five steps:
use mathcore::prelude::*;
use mathcore::MathCore;

fn main() {
    let math = MathCore::new();

    // --- arithmetic ---
    println!("2 + 3 * 4 = {}", math.calculate("2 + 3 * 4").unwrap());   // 14
    println!("(2 + 3) * 4 = {}", math.calculate("(2 + 3) * 4").unwrap()); // 20
    println!("2^8 = {}", math.calculate("2^8").unwrap());                 // 256

    // --- variables ---
    let mut vars = HashMap::new();
    vars.insert("x".to_string(), 3.0);
    vars.insert("y".to_string(), 4.0);
    let dist = math.evaluate_with_vars("sqrt(x^2 + y^2)", &vars).unwrap();
    println!("sqrt(3² + 4²) = {}", dist); // 5

    // --- differentiation ---
    let deriv = MathCore::differentiate("x^2 + 2*x + 1", "x").unwrap();
    println!("d/dx(x^2 + 2*x + 1) = {}", deriv); // 2*x + 2

    // --- equation solving ---
    let roots = MathCore::solve("x^2 - 4", "x").unwrap();
    println!("roots of x^2 - 4 = 0: {:?}", roots); // [2, -2]

    // --- integration ---
    let integral = MathCore::integrate("x^2", "x").unwrap();
    println!("∫x² dx = {}", integral);

    let area = MathCore::numerical_integrate("x^2", "x", 0.0, 1.0).unwrap();
    println!("∫₀¹ x² dx = {:.6}", area); // ≈ 0.333333
}
Run it with:
cargo run

Next Steps

Calculus & Differentiation

Symbolic and numerical differentiation, limits, Taylor series, and integration by parts.

Algebra & Equation Solving

Solve linear, quadratic, and higher-degree equations; factor and simplify expressions.

Matrix Operations

Symbolic matrices, determinants, eigenvalues, decompositions, and linear-system solvers.

API Reference

Full API documentation for all public types, methods, and modules in MathCore.

Build docs developers (and LLMs) love