Metadata-Version: 2.4
Name: diffstep
Version: 1.4.0
Summary: A symbolic differentiation library.
Home-page: https://campus.cs.le.ac.uk/gitlab/ug_project/25-26/aoe8
Author: Ayo
Author-email: Ayo <akoitilo@gmail.com>
License: Copyright 2025 Ayo Emmanuel
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dynamic: author
Dynamic: home-page
Dynamic: license-file

# diffstep

diffstep is a small Python library for math derivatives.

It helps you:

- Find the derivative of math expressions.
- Get the derivative value at a given x value.
- Print a tree view of the expression.
- Print the steps used to get the derivative.

## Installation

```bash
pip install diffstep
```

## Quick Start

```python
import diffstep

diffstep.diffstep("x^2 + 3x + 2")
# 2*x + 3

diffstep.gradient("x^2 + 3x + 2", 1)
# 5

diffstep.diffstep("x^x")
# x^x*(log(x) + 1)

diffstep.parse_expression("sin(x) + cos(x)")
# Prints pretty AST once and returns None

diffstep.trace("x^2 + sin(x^2)")
# Prints rendered trace text once and returns None
```

## Public API

- `diffstep(expression: str)`
  Returns the simplified symbolic derivative as a SymPy expression.

- `differentiate(expression: str)`
  Alias of `diffstep()`.

- `gradient(expression: str, x_value: float)`
  Differentiates, then evaluates at `x = x_value`.

- `normalise_expression(expression: str)`
  Validates and normalizes expression text (spaces, implicit multiplication, casing).

- `tokenise_expression(expression: str)`
  Returns the token list after normalization.

- `parse_expression(expression: str, pretty: bool | None = None, emit: bool = True)`
  If `pretty=False`, it returns the raw parse tree object.
  In other cases, it prints a readable tree and returns `None`.
  If you set `emit=False`, it does not print and returns the tree as text.

- `pretty_parse_expression(expression: str, emit: bool = True)`
  Convenience wrapper for `parse_expression(expression, pretty=True)`.

- `derived_ast(expression: str)`
  Returns unsimplified derivative AST.

- `trace(expression: str)`
  Prints rendered differentiation trace text and returns `None`.

- `DiffStep(expression: str)`
  Deprecated alias of `diffstep()` (emits `DeprecationWarning`).

## Supported Expressions

- Variables: `x`, `e`
- Numeric constants (integers and decimals)
- Operators: `+`, `-`, `*`, `/`, `^`
- Parentheses and implicit multiplication (for example `2x`, `x(x+1)`)
- Power forms including:
  - `x^n`
  - `a^f(x)`
  - `e^f(x)`
  - General `u(x)^v(x)` (for example `x^x`)
- Functions:
  - `sin`, `cos`, `tan`
  - `sec`, `cosec`, `cot`
  - `arcsin`, `arccos`, `arctan`
  - `ln`, `sqrt`

## Project Layout

- `diffstep/core/`: normalization, tokenization, parsing, AST nodes
- `diffstep/differentiation/`: derivative and trace rule engines
- `diffstep/simplify/`: SymPy-backed simplification
- `diffstep/printer/`: AST and trace rendering utilities
- `diffstep/pipeline.py`: user-facing orchestration API

## License

MIT License. See `LICENSE.txt`.
