0

I have a source file like (without loss of generality (only to image a possible syntax)):

function a()
    return g // global variable without any internal structure exactly
end

function b(x, y)
    local z = x * y
    return z + 1
end

function c(z, t)
    return b(z * z, a())
end

// ...etc

I want to defferentiate any function WRT to some variable.

All the formal parametres we can treat as a functions with unknown at derive time internal structure.

If I stand correct further, then the following is truth (for depending symbols ' is part of symbol, for global variables is operator during substitute time stage (def: g{g} is one, but g{y} is zero)):

function a'()
    return g';
end

function b'(x, y, x', y')
    local z' = x' * y + x * y'
    return z' + 0
end

But what to do with last function? Namely, with actual parameters in substitution of function b?

Is there any ready to use implementations of general algorithm to work with the above? What to do with higher order derivatives (especially interesting, how to handle the formal parameters)? Are there any other possible unclear cases?

Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169

1 Answers1

1

I would suggest having your parameters be symbolic expressions that know how to respond to derivatives, and having all operations take functions and return functions. Then you will get a final expression that knows how to be represented as a derivative. Furthermore you can do things like partial derivatives at a later point because you have the symbolic expression.

For a real example of what I mean, see http://www.elem.com/~btilly/kelly-criterion/js/advanced-math.js for a library that I wrote to solve a calculus problem in JavaScript, and search for "Optimize if requested" in the source for http://www.elem.com/~btilly/kelly-criterion/betting-returns2.html to see how I used it. See http://www.elem.com/~btilly/kelly-criterion/ for an explanation of why I was writing that code.

In that example I, of course, was not working from infix notation. But that is a standard parsing problem that I think you know how to solve.

btilly
  • 43,296
  • 3
  • 59
  • 88