I need to define many variants of a function which take special values when any of the arguments are zero (or the calculation can be significantly simplified). I can imagine this can be done programmatically, but so far I have not found how.
For example, consider the following example:
f[0, 0] = 0;
f[x_, 0] = Integrate[foo[xx, 0], {xx, 0, x}];
f[0, y_] = Integrate[foo[0, yy], {yy, 0, y}];
f[x_, y_] = Integrate[foo[xx, yy], {xx, 0, x}, {yy, 0, y}];
This is already a little annoying to do with 2 arguments, but I need to do something similar with a 6-function arguments...
Any hint as to how this can be done?
Even better, I'm defining these functions within another function and thus I know which argument(s) will be zero at run time. Thus I have currently something like:
process[f[n_, m_, a_, b_]] := Block[{disc},
disc[0, 0] = 0;
disc[x_, 0] = Sum[auxFunction[f[n, m, x, 0], v], {v, {x}}];
disc[0, y_] = Sum[auxFunction[f[n, m, 0, y], v], {v, {y}}];
disc[x_, y_] = Sum[auxFunction[f[n, m, x, y], v], {v, {x, y}}];
disc[a, b] / (2 I)
];
It is clear that as the Block
is being evaluated, I will know which of a
and/or b
will be 0
thus only one of the 4 variants needs to be computed.