A symbolic differentiation library.
Project description
diffstep
diffstep is a lightweight Python library for algorithmic differentiation.
It lets you:
- Differentiate expressions like
x^2 + 3x + 2 - Evaluate gradients at specific points
Installation
Install from PyPI:
pip install diffstep
Quick Start
Basic Access (from diffstep import diffstep)
from diffstep import diffstep
diffstep("x^2 + 3x + 2")
# 2*x + 3
Advanced Access (import diffstep)
import diffstep
diffstep.differentiate("x^2 + 3x + 2")
# 2*x + 3
diffstep.gradient("x^2 + 3x + 2", 1)
# 5
diffstep.parse_expression("sin(x) + cos(x)")
# Prints a readable AST tree
Public API
-
diffstep(expression: str)Main entry point. Returns the simplified symbolic derivative. -
differentiate(expression: str)Alias ofdiffstep(). -
gradient(expression: str, x_value: float)Evaluates the derivative at a specificxvalue. -
normalise_expression(expression: str)Returns the normalized expression string used internally by the parser. -
parse_expression(expression: str, pretty: bool | None = None)Parses an expression to AST form. By default, it prints a pretty ASCII tree. Passpretty=Falseto return the raw AST node instead. -
DiffStep(expression: str)Deprecated alias for backward compatibility.
Supported Expression Features
- Variables:
x - Constants and arithmetic:
+,-,*,/,^ - Common functions such as
sin,cosec,arctan,ln, andsqrt
Project Structure
diffstep/core/: validation, tokenization, parsing, AST nodesdiffstep/differentiation/: differentiation rulesdiffstep/simplify/: simplification logicdiffstep/printer/: AST-to-expression string conversiondiffstep/pipeline.py: user-facing workflow functions
License
MIT License. See LICENSE.txt for details.
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 diffstep-1.3.0.tar.gz.
File metadata
- Download URL: diffstep-1.3.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20521fdb417a72ddffd61eb97d8a5e65289a8a35fbf1331af016900067f0bdfb
|
|
| MD5 |
ed2848d44ece5238891ecd8248b3193f
|
|
| BLAKE2b-256 |
1db0bf02d5988d67efc75621180f4f882f8d518883934435888580beec5c8a74
|
File details
Details for the file diffstep-1.3.0-py3-none-any.whl.
File metadata
- Download URL: diffstep-1.3.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebf0ce9d0dff19fe4512ef111ccaef9d0bdebdcd6a9de4408767bfad6dfa4b6e
|
|
| MD5 |
2560a9a859bb6182fdd74131f2112e79
|
|
| BLAKE2b-256 |
904f40b5f19bc5fc2cb1a577a093a4752577bdf2cb01a1de62da9f6e826b59c3
|