Skip to main content

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 of diffstep().

  • gradient(expression: str, x_value: float) Evaluates the derivative at a specific x value.

  • 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. Pass pretty=False to 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, and sqrt

Project Structure

  • diffstep/core/: validation, tokenization, parsing, AST nodes
  • diffstep/differentiation/: differentiation rules
  • diffstep/simplify/: simplification logic
  • diffstep/printer/: AST-to-expression string conversion
  • diffstep/pipeline.py: user-facing workflow functions

License

MIT License. See LICENSE.txt for details.

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

diffstep-1.3.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

diffstep-1.3.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

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

Hashes for diffstep-1.3.0.tar.gz
Algorithm Hash digest
SHA256 20521fdb417a72ddffd61eb97d8a5e65289a8a35fbf1331af016900067f0bdfb
MD5 ed2848d44ece5238891ecd8248b3193f
BLAKE2b-256 1db0bf02d5988d67efc75621180f4f882f8d518883934435888580beec5c8a74

See more details on using hashes here.

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

Hashes for diffstep-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebf0ce9d0dff19fe4512ef111ccaef9d0bdebdcd6a9de4408767bfad6dfa4b6e
MD5 2560a9a859bb6182fdd74131f2112e79
BLAKE2b-256 904f40b5f19bc5fc2cb1a577a093a4752577bdf2cb01a1de62da9f6e826b59c3

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