Skip to main content

delta-dx

PYPI Version Publish to PYPI Run Python Tests

Author : MrRhuezzler
Project Language : Python
Project Year : 2021

How to Install

This currently avaiable on PYPI, from where it can be installed using the following command.
(Note : pip and python must be added to the PATH for this command to work)

pip install delta-dx

Usage

from delta import Expression
expression = Expression("x * e ^ x")
print(Expression.differentiate(expression, nth_derivative=1))

Approach

This Project uses all the basic rules of Mathematical Differentiation and converts them into a computer algorithm, which provides the power to differentiate various equations. One main advantage of this project is that it can differentiate between variables ( x, y, z, w, u, v ) and numbers (5, 0.56, e, pi, tau ).

Thinking of devising an algorithm to handle such a task is the goal, luckily Dynamic Programming can be used to devise such an algorithm. Let's take an example to explain.

Example:

d(sin(2x)) / dx = cos(2x) * 2

In the equation sin(2x), first we differentiate based on the rule d(sin(u)) / dx =cos(u) and then followed by differentiating u = 2x based on the rule d(cv) / dx = c dv/dx we get 2.

From the above example, we can see that the process of differentiating sin(2x)is being broken down to first differentiating the outer sin(u) function and differentiating the inner 2x function and then combining both results to get the answer to the given problem.

The Next major problem is that, how is an equation being represented in the computer algorithm. To Tackle this problem, we have to see the various ways that an expression can be expressed. They are infix, prefix, postfix notations.

Example:

(a+b) * (c + d) - Infix
*+ab+cd         - Prefix
ab+cd+*         - Postfix

Given the input expression, it can be converted to the prefix notation, with can be easily converted into a prefix expression tree, which can be used as an input to the algorithm and also devise the algorithm in such a way that it outputs a prefix expression tree, which makes it complete cycle (Enabling the algorithm to find multiorder derivatives).

Example:

log 10(cos(5 * x))

Expression Tree :

        log
      /     \
    10        cos
                \ 
                 *
                /  \ 
              5     x

By traversing the tree layer by layer and calling the algorithm, to solve for each layer, the problem of differentiating becomes a lot simpler. Let's take an example of differentiating a mathematical expression.

Example:

sin(2*x)

Expression Tree

    sin
      |
      *
    /   \
  2       x
-> differentiate(sin) // Calling the algorithm to solve
-> if input == sin // If the given head node of the tree represents sin function
->    cos = cos // Creating a node representing cos function
->    cos.child = input.child // Assigning the input for cos function
->     multiply = * // Creating a multiplication node
->    multiply.left = cos
->    multiply.right = differentiate(input.child) // Recursively calling the algorithm to solve for 2*x
->      return multiply // returning the result
-> if input == * // If the input is a multiplication operation
->     // Statements to handle this case and return the result.
-> done

Now we are done with the differentiating algorithm.

The Next steps may be to simplify the output of the differentiating algorithm, so that it looks neat and simple, rather than having more additional terms in the final output expression. Such an expression folding algorithm is also implemented to fold into smaller expressions. And with some basic mathematics an algorithm was devised. It is not the most optimal solution for the problem. I learnt many things in making this package.

Resources

Metadata

Release files for delta-dx 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for delta-dx 0.1.2
File Size Uploaded
delta-dx-0.1.2.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for delta-dx 0.1.2
File Interpreter ABI Platform
delta_dx-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.0 kB

Release files / delta-dx-0.1.2.tar.gz

Download URL delta-dx-0.1.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f4b9a834e6bb77cb20ac81a75f77158e4752742c621c731e9e41dec66bdec775
BLAKE2b-256 checksum
How to use checksums
66e7137b1828e8b48593250924d4f1f17c94ee11ccfb012931a0a9d304f41810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / delta_dx-0.1.2-py3-none-any.whl

Download URL delta_dx-0.1.2-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ce7fed1ea7faa698fafe2909dcfbf5ca5397980b1fd63b6e176b621b7735a00
BLAKE2b-256 checksum
How to use checksums
ddab1470e057e934e5589982e87fd0f6eb90e8ad24bd4c0bbaa16440930f7859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page