A symbolic differentiation library.
Project description
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
pip install diffstep
Quick Start
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 ofdiffstep(). -
gradient(expression: str, x_value: float)Differentiates, then evaluates atx = 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)Ifpretty=False, it returns the raw parse tree object. In other cases, it prints a readable tree and returnsNone. If you setemit=False, it does not print and returns the tree as text. -
pretty_parse_expression(expression: str, emit: bool = True)Convenience wrapper forparse_expression(expression, pretty=True). -
derived_ast(expression: str)Returns unsimplified derivative AST. -
trace(expression: str)Prints rendered differentiation trace text and returnsNone. -
DiffStep(expression: str)Deprecated alias ofdiffstep()(emitsDeprecationWarning).
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^na^f(x)e^f(x)- General
u(x)^v(x)(for examplex^x)
- Functions:
sin,cos,tansec,cosec,cotarcsin,arccos,arctanln,sqrt
Project Layout
diffstep/core/: normalization, tokenization, parsing, AST nodesdiffstep/differentiation/: derivative and trace rule enginesdiffstep/simplify/: SymPy-backed simplificationdiffstep/printer/: AST and trace rendering utilitiesdiffstep/pipeline.py: user-facing orchestration API
License
MIT License. See LICENSE.txt.
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.4.0.tar.gz.
File metadata
- Download URL: diffstep-1.4.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e964cf6fb47e062227cf7d875848e3ef04730e662de37238b1d680a005118808
|
|
| MD5 |
0b7e0b15675fbb299272f44e055d1687
|
|
| BLAKE2b-256 |
22c281cb3987b02579ce663b8ad55dc143c275c5c7ceb95a6f82ca43c51d12ec
|
File details
Details for the file diffstep-1.4.0-py3-none-any.whl.
File metadata
- Download URL: diffstep-1.4.0-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32586efd9280e35b4873c81669375256282e2d806081640123ccecfaf9234dc8
|
|
| MD5 |
734c537b3e5f02b98abb5458c44e43e2
|
|
| BLAKE2b-256 |
468b030f0df8462095267f4f259f41e327567c0551bbc8d6bcb536d50b02dd5a
|