I want to define a function evaluate[f_[x__]] which acts on an arbitrary function f[a,b,c,d]. The function f takes any kind of argument and the function evaluate[f_[x__]] has to deal with the following properties
- The function
fis defined for specific values fora,b,c,d, which may be numbers, list, functions etc.. For example,consider the definitionsf[1,2,3,4]=1andf[1,2,p[3],p[4]]=2wherep[a_]are undefined functions/tensors. Notice the order matters.
I want the function evaluate returning the function f evaluated on the specific permutation for which I have given a definition of f itself. For example,
evaluate[f[3,4,1,2]]must returnf[1,2,3,4]=1since among the permutations of{3,4,1,2},fis only defined on{1,2,3,4}.evaluate[f[p[3],p[4],1,2]]must returnf[1,2,p[3],p[4]]=2since among the permutations of{p[3],p[4],1,2},fis only defined on{1,2,p[3],p[4]}.evaluate[f[x__]]must returnFalseis multiple permutations are defined and if no permutations are matched.
Is there any intelligent and clever way to write a function with these properties?