I'm trying to define functions using other functions, like so:

f[a_, b_] := a/b;
a[c_] := c;
b[d_] := d;

Now what I want to be able to do is two things:

  1. Solving f[a_,b_] for c so that the output is c=f*d
  2. Deriving f[a_,b_] directly for c so that the output is similar to this: D[f[a_,b_],c_]=1/d

As you can tell, my knowledge on defining functions properly is pretty shaky, I'm sure there is a very simple solution to this that I'm just not nearly experienced for to think of it.

Thanks -A Mathematica beginner


2 Answers 2


Not sure if I've understand you. Something like this?:

With[{a = a[c], b = b[d]}, D[f[a, b], c]]
With[{a = a[c], b = b[d]}, Solve[f == f[a, b], c]]
{{c -> d f}}
  • $\begingroup$ That seems to do the trick, thanks! I circumvented using the "with" notation by defining f[a_,b_] as a[c]/b[d], is there any downside to doing this? $\endgroup$
    – F. E.
    Commented Apr 27, 2015 at 8:26
  • 1
    $\begingroup$ @F.E. I don't think there's any serious downside, it's just OK to use a[c] and b[d] directly. Of course it's better to use With when there's a lot of a[c]/b[d] to write. $\endgroup$
    – xzczd
    Commented Apr 27, 2015 at 8:33
  • $\begingroup$ Great, thank you so much! $\endgroup$
    – F. E.
    Commented Apr 27, 2015 at 8:38

Calculations about equality

There are different kinds of "equality" used in computer programming. In Mathematica, ==, or Equal is used to assert equality. 1==1 is a True statement, and 1==2 is False. f == a/b is a statement about the relationship between f, a and b.

You shouldn't use := to assert equality between f and a/b or c/d. Rather, make the assertion like this:

f == a[c]/b[d]
(*produces f == c/d *)

Solve[ f == a[c]/b[d], c]
(* {{ c -> d f }} *)

Calculations using the functions

The syntax := means SetDelayed, so when you say f[a_, b_] := a/b you are instructing Mathematica (as opposed to asserting) to replace f[x,y] with x/y.

Your second question could be rephrased as "how do I instruct Mathematica to call the functions f, a and b so that my derivative is calculated". Answer: when you call f[a[c], b[d]] it will evaluate into c/d so that

D[f[a[c], b[d]], c]
(* produces 1/d *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.