0
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ You know what, it is working for me now! Wasn't before... Thank you! No idea what happened there... $\endgroup$ – wilsnunn Sep 28 '18 at 1:05
  • $\begingroup$ @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. $\endgroup$ – enano9314 Sep 28 '18 at 16:42
  • $\begingroup$ 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. $\endgroup$ – wilsnunn Sep 28 '18 at 20:49

Your Answer

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

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