I am trying to convert Mathematica output into equations I can plug into C. I am presently trying to convert expressions of the form


where f is function with an arbitrary name (e.g. it may be called f, g, func, etc), into expressions of the form


where f is the symbol for the original function, e.g. I want the general rule to map Derivative[1,0,0][g][t,x,y] to g_Dt as well. Is there a way of doing this? For example, applying


(where "expression" is arbitrary) doesn't work.

To expand the scope of this question, more generally I would like to transform


to not just f_Dt, but also expressions like




(i.e. expressions that don't just include the underscore after f).

  • $\begingroup$ Well if it's Derivative[1,0,0][f][t,x,y] then Derivative[1,0,0][f_][T,R,Y] clearly won't match that. Maybe you wanted Derivative[1,0,0][f_][a_, b_, c_]? By the way, why are you trying to transform it into something that looks like f_Dy? If you look at the FullForm[f_Dy] you get Pattern[f, Blank[Dy]] which is a pattern matching object and thus something that can't be used as a function name or anything like that. $\endgroup$
    – b3m2a1
    Dec 11 '19 at 18:34
  • $\begingroup$ @b3m2a1 Unfortunatelyt the [T,R,Y] is a typo (which I've corrected). I want to transform to something like f_Dy as that is the general name for a function derivative I am using in my C code. $\endgroup$ Dec 11 '19 at 18:47
  • 1
    $\begingroup$ Can you give us a sample expression where this fails? I'm almost certain your pattern just isn't quite flexible enough for what you want. Like you expect one form of the pattern but it turns out you have a different one. $\endgroup$
    – b3m2a1
    Dec 11 '19 at 18:48
  • $\begingroup$ In version 10.1 Derivative[1, 0, 0][foo][t, x, y] /. {Derivative[1, 0, 0][f_][t, x, y] :> f_Dt} yields foo_Dt along with a warning message that in this case can be ignored. $\endgroup$
    – Mr.Wizard
    Dec 11 '19 at 20:25
  • $\begingroup$ @Mr.Wizard For some reason that approach isn't working for more complicated algebraic expressions that also include derivatives of other functions (e.g. the expression includes derivatives of a function f, h, etc) .I'm also concerned by the warning Mathematica raises. $\endgroup$ Dec 19 '19 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.