Skip to main content

A tiny library that catches invalid math operations and explains why they failed.

Project description

ExplainMath

ExplainMath is a small Python library that catches invalid numeric operations (like division by zero, undefined results, or bad power operations) and explains why it went wrong in plain English — instead of silently giving NaN or inf.

This is useful in machine learning, simulations, finance, or any code where one wrong number can poison the whole pipeline without you noticing.


🔥 Why This Library Exists

In Python, many invalid numeric operations do not crash your program. Instead, they produce NaN, inf, or a complex number — and these values spread quietly through your code.

Example of a real problem:

```python result = model(data) print(result) # nan ... now what?

Traditional debugging tells you where the error happened,

but not why the math became invalid.

ExplainMath catches the failure at the moment it happens and tells you the reason.

```

✨ Features

  • Tracks invalid math operations
  • Supports addition, subtraction, multiplication, division, and power
  • Marks invalid values explicitly (no hidden NaNs or silent errors)
  • Preserves the reason for the failure
  • Propagates invalid state safely through further calculations
  • Optional .require() strict mode that raises an exception

🚀 Quick Start

📦 Examples

Basic addition

```python from explainmath import Value

a = Value(10) b = Value(5) print(a.add(b).value) # 15 ```

Invalid Division

```python from explainmath import Value

a = Value(10) b = Value(0) c = a.div(b) print(c.is_valid()) # False print(c.explanation) # "Division by zero while evaluating 10 / 0" ```

🔒 Strict Mode Example (Fail Fast)

```python from explainmath import Value, SemanticError

try: Value(10).div(Value(0)).require() except SemanticError as e: print("Error caught:", e) ```

🧪 Running Tests

```bash python -m unittest discover -v ```

📌 Project Status

This is version v0.1. It is intentionally small and focused:

  • A single numeric type
  • Basic arithmetic
  • Error explanation
  • Safe propagation

Future versions will include:

  • Operation history
  • Provenance tracking
  • Better debugging reports
  • Optional integration with NumPy/PyTorch

🗂 Folder Structure

```text core/ → implementation examples/ → usage demos tests/ → unit tests docs/ → (reserved for future) ```

License

This project is licensed under the MIT License.


Made with curiosity, logic, and a desire to reduce silent math bugs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

explainmath-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

explainmath-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file explainmath-0.1.1.tar.gz.

File metadata

  • Download URL: explainmath-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for explainmath-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2ac1ace46d19e710842edb9f53b67c8672c98d21d99e4e40d72f57e23f21e4ad
MD5 f5535505d795ec7e7c77e08f131ab741
BLAKE2b-256 f8e9756ef32c5c7fc16feabbf2ea8696a8c7df63341e43a9c805679a056b5026

See more details on using hashes here.

File details

Details for the file explainmath-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: explainmath-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for explainmath-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 054d95c270376bb1912ba2c41e845b23a79e8541d1f1ef007a8e656c7f4b20c8
MD5 690caf708303828be5036cad3ea43ca9
BLAKE2b-256 038566dbc9c03013012157c9d0eaef28e1b85fa4d47c5b32112aa7f0a2f80392

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page