# Defining a function on the difference of two inputs

Sorry if this is already on this forum somewhere, I had a look but couldn't find anything. Anyway, I am looking to define a function where the inputs are: a and b-c. Is there any way to do this?

MWE:

foo[x_Symbol,y_Symbol]:=z
foo[a_Symbol,(b_Symbol-c_Symbol)]:=foo[a,b]-foo[a,c]


The (b_Symbol-c_Symbol) is the output of another function that I have.

This already seems to work for me as you have it

foo[x_Symbol, y_Symbol] := z
foo[a_Symbol, (b_Symbol - c_Symbol)] := foo[a, b] - foo[a, c]

foo[x, y]


z

foo[x, y - z]


0

Though perhaps you could give more details and we could see what you want to do with this code?

• You know what, it is working for me now! Wasn't before... Thank you! No idea what happened there... – wilsnunn Sep 28 '18 at 1:05
• @DanielWilson-Nunn it was probably that you had an old Downvalue sitting around. It is generally a pretty good idea to ClearAll[<your function name here>] to make sure you don't have old definitions sitting around. – enano9314 Sep 28 '18 at 16:42
• I always do a ClearAll before defining the function (I didn't in my MWE though) so I don't think it would have been that. But thank you anyway. – wilsnunn Sep 28 '18 at 20:49