It seems that what you are interested in is how to attach 'special' definitions for a given function. By this I mean the need to allow eg $y e^\frac{x}{y}$ evaluate normally for all values of $x$ and values of $y$ other than $0$ while making it evaluate to $0$ whenever $y$ is $0$ (the other function can be treated in principle with the same approach so it won't be discussed further).
There are more than a handful of ways to achieve such an effect in MA/WL, two of which-the most straightforward IMHO-I'll display in what follows.
The first way to achieve the desired effect is to construct a function with different 'branches' for the different cases you are interested in.
To that effect you can use Piecewise
:
f[x_,y_]:=Piecewise[{
{y e^(x/y), y!=0},
{0, y==0}},
$Failed
]
A couple of notes on f
:
Inputs are assumed to be numerical quantities. This is implicit but could be defined more rigorously if that is desired (potential ways to do that with minor adjustments in f
would include PatternTest
's on the inputs or incorporating numeric checks (eg using NumericQ
) within Piecewise
branches-there are still more ways to achieve this eg using Condition
).
Related to this is that f
will return $Failed
with symbolic inputs for y
. More rigorous (and probably more demanding) definitions of f
could involve Attribute
NumericFunction
but this is probably excessive for the current context.
Finally, similar results can be obtained with Which
.
The second way to achieve similar effects with f
above, is to make use of how MA/WL uses/matches patterns.
When evaluating an expression, all known definions are applied on the input until it no longer changes (this is a simplified way to put it but it suffices for the task at hand).
MA/WL uses specific definitions before more general ones during evaluation. To that effect g[x_,0]=0
is more specific than g[x_,y_]:=y Exp[x/y]
.
Evaluating these definitions will let MA/WL 'know' that expressions like g[_,0]
are more specific than expressions like g[a,b]
so when it encounters patterns like the former, it will supply the 'correct' replacement ie $0$ instead of the full definition of $y e^\frac{x}{y}$.
Obviously, numeric constraints and similar considerations to those presented in the first approach are relevant to this approach, too.