AI Calculator Agent
Project description
Mathemagic
An AI calculator agent that interprets and solves science, technology, mathematics, and engineering problems in Python.
Features
- Converts natural language math problems to Python code using LLMs (Claude is currently the only supported model)
- Handles units using the Pint library
- Provides access through MCP and CLI interfaces
- Supports complex mathematical operations with proper unit handling
Examples
- "Convert 100 kilometers per hour to miles per hour"
- "What is the volume of a cylinder with radius 5cm and height 10cm?"
- "If I have 3 apples and 4 oranges, how many pieces of fruit do I have?"
- "Calculate the kinetic energy of a 2kg object moving at 10 meters per second"
Basic Usage
Enter command to start CLI
mathemagic
CLI initializes, and you type in your math problem
Mathemagic Calculator (Press Ctrl+C to exit)
Enter your math problem:
: Two hundred miles times 634 feet in meters squared.
Processing: Two hundred miles times 634 feet in meters squared.
Result:
62198956.89216 meter ** 2
Installation
# Clone the repository
git clone https://github.com/yourusername/mathemagic.git
cd mathemagic
# Install dependencies using UV
uv pip install -e .
Set up environment variables. Create a .env file with your Anthropic API key in the project root directory.
echo "ANTHROPIC_API_KEY=your_api_key_here" >> .env
Usage
Using the CLI
# Run in interactive mode
mathemagic
# Run the CLI with a math problem
mathemagic "100 miles times 234 acres in liters"
# Show the generated Python code along with the result
mathemagic "100 miles times 234 acres in liters" --output-python
# help menu
mathemagic --help
Output the Executed Python Code
Using the -p or --output-python flags
mathemagic -p
Mathemagic Calculator (Press Ctrl+C to exit)
Enter your math problem:
: Two hundred miles times 634 feet in meters squared.
Processing: Two hundred miles times 634 feet in meters squared.
Generated Python code:
```python
from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
# Define the variables with their respective units
miles = Q_(200, 'mile') # distance in miles
feet = Q_(634, 'foot') # distance in feet
# Perform the multiplication
result = miles * feet
# Convert the result to meters squared
result_m2 = result.to('meter**2')
print(result_m2)
```
Result:
62198956.89216 meter ** 2
Handles Arbitrary Units
mathemagic uses Pint to handle units.
Enter another problem:
: 100 bananas times 66 guavas
Processing: 100 bananas times 66 guavas
Result:
6600 banana * guava
Using the MCP Server
Starting the Server
# Start the MCP server
uv run src/mathemagic/server.py
Add the MCP Server to Claude Code
Assuming you have claude code installed, type this command, then follow the wizard. You'll enter the command above when prompted.
claude mcp add
Architecture
The application consists of:
mathemagic.py: Core functionality for converting natural language to Python code and executing itserver.py: MCP server that provides API endpoints for the calculatorcli.py: Command-line interface for interacting with the calculator
TODO
- Clean up python output through server (currently outputs in a dict and not pretty)
- Improve CLI (make it pretty)
- Add symbolic math support
- Add linear algebra support
- Update to use openrouter
- Add tests
- Astropy support?
- Auth as alternative to .env for remote use?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathemagic_ai-0.1.0.tar.gz.
File metadata
- Download URL: mathemagic_ai-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9746b7683ed8515ed1339725dfa407492612e3a8937e25a3a3c80f15bf9993cf
|
|
| MD5 |
99838bebc60d638d492db340874f4db7
|
|
| BLAKE2b-256 |
27e3cef8fd79b3e6eb1b9978b3dab71be12a3bc2b12d51ead544e3c1a96c72a7
|
Provenance
The following attestation bundles were made for mathemagic_ai-0.1.0.tar.gz:
Publisher:
publish.yml on CPME/mathemagic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathemagic_ai-0.1.0.tar.gz -
Subject digest:
9746b7683ed8515ed1339725dfa407492612e3a8937e25a3a3c80f15bf9993cf - Sigstore transparency entry: 189946806
- Sigstore integration time:
-
Permalink:
CPME/mathemagic@47100ca632a358896d019238f80391bd72b55a7e -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/CPME
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@47100ca632a358896d019238f80391bd72b55a7e -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathemagic_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mathemagic_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc4a4c24f2d5e286bf758248b76e3c9bb6d1e70dede7b2c2b8fe643df8fea7a3
|
|
| MD5 |
7700302604eb29d82c2c08d9f57f135c
|
|
| BLAKE2b-256 |
e4e5776621c0f8572a69a478034e6be4f63fe09cd8cb2fd244fe48b42e314540
|
Provenance
The following attestation bundles were made for mathemagic_ai-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on CPME/mathemagic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathemagic_ai-0.1.0-py3-none-any.whl -
Subject digest:
fc4a4c24f2d5e286bf758248b76e3c9bb6d1e70dede7b2c2b8fe643df8fea7a3 - Sigstore transparency entry: 189946807
- Sigstore integration time:
-
Permalink:
CPME/mathemagic@47100ca632a358896d019238f80391bd72b55a7e -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/CPME
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@47100ca632a358896d019238f80391bd72b55a7e -
Trigger Event:
push
-
Statement type: