Metadata-Version: 2.4
Name: mathrobo
Version: 0.0.2
Summary: basic mathematical library for robotics reserach
Project-URL: Homepage, https://github.com/MathRobotics/MathRobo
Author-email: taiki-ishigaki <taiki000ishigaki@gmail.com>
License: MIT License
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Requires-Dist: jax>=0.4.30
Requires-Dist: numpy>=2.0.2
Requires-Dist: pytest>=8.4.2
Requires-Dist: scipy>=1.13.1
Requires-Dist: sympy>=1.14.0
Description-Content-Type: text/markdown

# Mathrobo

Mathrobo is a lightweight library designed to support mathematical optimization and computations related to robotics.

## Installation

### Clone the repository

```bash
git clone https://github.com/MathRobotics/MathRobo.git
cd MathRobo
```

### Install dependencies with uv

Sync the environment from `pyproject.toml` and `uv.lock`:

```bash
uv sync
```

### Install the package in editable mode

```bash
uv pip install -e .
```

## Examples
Refer to the examples in the `examples` folder, where you can find Jupyter notebooks and scripts demonstrating various use cases of the library.

## Usage

You can also work with spatial transformations using the `SE3` class. The
following snippet creates a 90 degree rotation around the Z axis with a
translation, applies the transformation to a point and then inverts it:

```python
import numpy as np
import mathrobo as mr

# Rotation of 90 deg about Z and translation of 1 m along X
rot = mr.SO3.exp(np.array([0.0, 0.0, 1.0]), np.pi / 2)
T = mr.SE3(rot, np.array([1.0, 0.0, 0.0]))

point = np.array([0.0, 1.0, 0.0])
transformed = T @ point
recovered = T.inv() @ transformed

print(transformed)
print(recovered)
```

Here is a quick example that computes the numerical gradient of a simple function:

```python
import numpy as np
import mathrobo as mr

f = lambda x: np.sum(x**2)
x = np.array([1.0, 2.0, -3.0])
grad = mr.numerical_grad(x, f)
print(grad)
```

You can also perform numerical integration using the Gaussian quadrature helper
`gq_integrate`:

```python
import numpy as np
import mathrobo as mr

f = lambda s: np.array([np.sin(s)])
val = mr.gq_integrate(f, 0.0, np.pi, digit=5)
print(val)  # ~ 2.0
```

For spline trajectories, SciPy's `BSpline` can be used to create and evaluate a
curve:

```python
import numpy as np
from scipy.interpolate import make_interp_spline

t = np.array([0, 1, 2, 3])
points = np.array([0.0, 1.0, 0.0, 1.0])
spl = make_interp_spline(t, points, k=3)

ts = np.linspace(0, 3, 20)
ys = spl(ts)
print(ys)
```

## Running Tests

Run the test suite with uv:

```bash
uv run pytest
```

## Contributing

Contributions are welcome! Feel free to report issues, suggest features, or submit pull requests.

## License

This project is licensed under the [MIT License](LICENSE).
