# Subsituting expressions for expressions

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

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]]

1/d
{{c -> d f}}

• 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? – F. E. Apr 27 '15 at 8:26
• @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. – xzczd Apr 27 '15 at 8:33
• Great, thank you so much! – F. E. Apr 27 '15 at 8:38

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 *)