Skip to main content
2 of 2
added 116 characters in body
apt45
  • 1.7k
  • 9
  • 18

Define a function with specific permutation properties

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 f is defined for specific values for a,b,c,d, which may be numbers, list, functions etc.. For example,consider the definitions f[1,2,3,4]=1 and f[1,2,p[3],p[4]]=2 where p[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 return f[1,2,3,4]=1 since among the permutations of {3,4,1,2}, f is only defined on {1,2,3,4}.
  • evaluate[f[p[3],p[4],1,2]] must return f[1,2,p[3],p[4]]=2 since among the permutations of {p[3],p[4],1,2}, f is only defined on {1,2,p[3],p[4]}.
  • evaluate[f[x__]] must return False is multiple permutations are defined and if no permutations are matched.

Is there any intelligent and clever way to write a function with these properties?

apt45
  • 1.7k
  • 9
  • 18