Matrix calculus differentiation



On 2013-10-02, Mike Valenzuela <mickle.mouse at gmail.com> wrote:

> A while back I tried taking a jab at converting some matrix calculus rules
> into maxima, but I'm not very good with Lisp. However, Paul Horsfall has
> been kind enough to point out the following source to me (
> http://zulko.wordpress.com/2012/04/15/symbolic-matrix-differentiation-with-sympy/).
>  I'm much better with Python and have found this to be incredibly useful.

Well, Maxima has some machinery to implement that kind of stuff, namely
user-defined simplification rules; pretty sure Lisp programming isn't
necessary. Maxima might be a little more natural for such stuff than
Sympy, to judge by the blog referenced above.

To take a random example from the Matrix Cookbook linked from that blog,
here is an implementation of eq 41.

(%i2) matchdeclare (Y, noncommutativep, x, symbolp) $
(%i3) noncommutativep (e) := featurep (e, nonscalar) or (not atom(e) and (op(e) = "." or op(e) = "^^")) $
(%i4) tellsimpafter ('diff ('determinant (Y), x), 'determinant(Y) * mat_trace (Y^^-1 . 'diff (Y, x))) $

so then we get:

(%i5) declare ([A, B], nonscalar) $
(%i6) depends ([A, B], u) $
(%i7) diff (determinant (A), u);
(%o7) 'determinant(A)*mat_trace(A^^(-1) . 'diff(A,u,1))
(%i8) diff (determinant (A . B), u);
(%o8) 'determinant(A . B)*mat_trace((A . B)^^(-1) . 'diff(A . B,u,1))

For any such identity, there would have to be a matchdeclare and a rule
definition (tellsimp, tellsimpafter, defrule, or defmatch).

best

Robert Dodier