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 fora,b,c,d
, which may be numbers, list, functions etc.. For example,consider the definitionsf[1,2,3,4]=1
andf[1,2,p[3],p[4]]=2
wherep[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]=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 returnf[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 returnFalse
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?
evaluate
to permute arguments off
(or any function?) to a form for which term rewriting finds a rule for arguments off
? What if there are multiple permutations which are permissible? $\endgroup$evaluate
to permute arguments of only the functionf
. It is supposed there are no multiple permutations which are permissible. I can add the requirement that if multiple permutations are permissible, returnFalse
. $\endgroup$False
. Let me edit the question $\endgroup$Orderless
, that isSetAttribute[f, Orderless]
forf
. This doesn't handle no-matches or multiple-matches cases, but can auto-permute arguments when evaluating the function. $\endgroup$