Proposal for "Math_Derivative"

» Metadata » Status
» Description
This package allows you to calculate the derivative of a mathematical expression.

Notice that expressions that are passed to it won't always be valid php syntax : "a^b" means "a raised to the power of b" for Math_Derivative and not the usual bitwise XOR.

That is important to know, especially if you plan to evaluate the expression returned using php's own eval().

Math_Derivative::getDerivative() will also work on literal expressions.

Predefined functions

Some functions are already implemented, so you can use them in the input:

  1. sin()
  2. cos()
  3. tan()
  4. ln() alias log()
  5. e()


Definding your own functions

Use Math_Derivative::registerFunction((string)name, (string)derivative form) to define your own functions.
The derivative form handle two special keywords: d() which means "getting the derivative of" and arg: the single argument passed to the function.
For example, the derivative form of e() would be : "d(arg)*e(arg)".

Note: You can nest multiple d(), I haven't found any case that could use this though.

Warning: enclose "arg" in parenthesis to ensure operators' precedence when needed.

Cache management

A cache management is already bundled to save intermediary results of the whole object, it provides a significant speed boost, especially when used with repetitive expressions. It is also allowed to save the cache and reuse it in another instance of the class.

You can also turn this cache system off.

Warning: Changing the dx, having caching enabled, will corrupt the cache. As a prevention method the entire cache will be flushed.

Simplification

Some simplification rules are aplied during the processing. There is currently no post-processing simplification system.
» Dependencies » Links
» Timeline » Changelog
  • First Draft: 2005-12-28
  • Proposal: 2006-01-04
  • Call for Votes: 2006-01-22
  • Voting Extended: 2006-01-30
  • Etienne Kneuss
    [2006-01-22 11:10 UTC]

    1) Math_Derivative is now PHP4 comaptible
    2) I removed the only dependency on ctype and replaced it with a simple regex.