| Crates.io | amari-calculus |
| lib.rs | amari-calculus |
| version | 0.17.0 |
| created_at | 2025-12-21 20:56:52.292917+00 |
| updated_at | 2026-01-11 22:41:53.440805+00 |
| description | Geometric calculus - unified differential and integral calculus using geometric algebra |
| homepage | |
| repository | https://github.com/justinelliottcobb/Amari |
| max_upload_size | |
| id | 1998581 |
| size | 143,193 |
Geometric calculus - a unified framework for differential and integral calculus using geometric algebra.
amari-calculus provides geometric calculus operations that unify vector calculus, differential forms, and tensor calculus into a single coherent framework. The key insight is that the vector derivative operator ∇ combines the familiar gradient, divergence, and curl operations into one fundamental operation.
Add to your Cargo.toml:
[dependencies]
amari-calculus = "0.12"
[dependencies]
# Default features
amari-calculus = "0.12"
# Minimal, no-std compatible
amari-calculus = { version = "0.12", default-features = false }
use amari_calculus::{ScalarField, VectorDerivative, CoordinateSystem};
// Define scalar field f(x, y, z) = x² + y²
let f = ScalarField::<3, 0, 0>::new(|coords| {
coords[0].powi(2) + coords[1].powi(2)
});
// Create vector derivative operator
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Compute gradient at point (1, 2, 0)
let grad_f = nabla.gradient(&f, &[1.0, 2.0, 0.0]);
// Gradient is approximately (2, 4, 0)
use amari_calculus::{VectorField, VectorDerivative, CoordinateSystem, vector_from_slice};
// Define vector field F(x, y, z) = (x, y, z)
let f = VectorField::<3, 0, 0>::new(|coords| {
vector_from_slice(&[coords[0], coords[1], coords[2]])
});
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Compute divergence (should be 3)
let div_f = nabla.divergence(&f, &[1.0, 1.0, 1.0]);
use amari_calculus::{VectorField, VectorDerivative, CoordinateSystem, vector_from_slice};
// Define vector field F(x, y, z) = (-y, x, 0) (rotation around z-axis)
let f = VectorField::<3, 0, 0>::new(|coords| {
vector_from_slice(&[-coords[1], coords[0], 0.0])
});
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Compute curl (returns bivector representing rotation)
let curl_f = nabla.curl(&f, &[0.0, 0.0, 0.0]);
// Curl is (0, 0, 2) as a bivector
The vector derivative operator is defined as:
∇ = eⁱ ∂ᵢ (sum over basis vectors)
This operator combines:
| Classical | Differential Forms | Geometric Calculus |
|---|---|---|
| grad f | df | ∇f |
| div F | ⋆d⋆F | ∇·F |
| curl F | ⋆dF | ∇∧F |
| ∇²f | ⋆d⋆df | ∇²f = ∇·∇f |
Geometric calculus has a single fundamental theorem that unifies all integral theorems:
∫_V (∇F) dV = ∮_∂V F dS
This single equation encompasses:
Scalar-valued functions on Cl(P,Q,R) space:
use amari_calculus::ScalarField;
// Temperature field T(x, y, z)
let temperature = ScalarField::<3, 0, 0>::new(|coords| {
100.0 * (-coords[0].powi(2) - coords[1].powi(2)).exp()
});
Vector-valued functions:
use amari_calculus::{VectorField, vector_from_slice};
// Velocity field
let velocity = VectorField::<3, 0, 0>::new(|coords| {
vector_from_slice(&[coords[1], -coords[0], 0.0])
});
General multivector-valued functions:
use amari_calculus::MultivectorField;
// Electromagnetic field (bivector field)
let em_field = MultivectorField::<3, 0, 0>::new(|coords| {
// Returns a multivector with bivector components
// ...
});
The ∇ operator:
use amari_calculus::{VectorDerivative, CoordinateSystem};
// Create in Cartesian coordinates
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Or in spherical coordinates
let nabla_sph = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Spherical);
| System | Coordinates | Use Case |
|---|---|---|
| Cartesian | (x, y, z) | General computations |
| Spherical | (r, θ, φ) | Central potentials |
| Cylindrical | (ρ, φ, z) | Axial symmetry |
| Polar | (r, θ) | 2D problems |
| Module | Description |
|---|---|
fields |
ScalarField, VectorField, MultivectorField |
operators |
gradient, divergence, curl, laplacian |
derivative |
VectorDerivative operator |
manifold |
RiemannianManifold, covariant derivatives |
lie |
Lie derivatives along vector fields |
integration |
ManifoldIntegrator |
use amari_calculus::prelude::*;
// Electric field E = -∇φ
let potential = ScalarField::<3, 0, 0>::new(|r| {
let r_mag = (r[0].powi(2) + r[1].powi(2) + r[2].powi(2)).sqrt();
1.0 / r_mag // Coulomb potential
});
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
let e_field = nabla.gradient(&potential, &[1.0, 0.0, 0.0]);
use amari_calculus::prelude::*;
// Velocity field
let velocity = VectorField::<3, 0, 0>::new(|r| {
vector_from_slice(&[r[1], -r[0], 0.0])
});
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Incompressibility: ∇·v = 0
let div_v = nabla.divergence(&velocity, &[1.0, 1.0, 0.0]);
// Vorticity: ω = ∇∧v
let vorticity = nabla.curl(&velocity, &[0.0, 0.0, 0.0]);
use amari_calculus::prelude::*;
// Temperature field
let temp = ScalarField::<3, 0, 0>::new(|r| {
(-r[0].powi(2) - r[1].powi(2) - r[2].powi(2)).exp()
});
let nabla = VectorDerivative::<3, 0, 0>::new(CoordinateSystem::Cartesian);
// Laplacian for heat diffusion
let laplacian_t = laplacian(&temp, &[0.0, 0.0, 0.0]);
For convenient imports:
use amari_calculus::prelude::*;
// Imports: ScalarField, VectorField, MultivectorField,
// VectorDerivative, CoordinateSystem,
// gradient, divergence, curl, laplacian
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
This crate is part of the Amari mathematical computing library.