Is there a way to write a replacement rule for a function f with an 
arbitrary number of arguments that makes it linear in all its arguments?
An example for when f has three arguments:

1) f( x1+x4 , x2 , x3 ) = f(x4,x2,x3) + f(x1,x2,x3)
2) f( x1 , x2+x4 , x3 ) = f(x1,x2,x3) + f(x1,x4,x3)
3) f( x1 , x2 , x3+x4 ) = f(x1,x2,x3) + f(x1,x2,x4)

Using "Wild" works partially:

from sympy import *
f=Function('f')
var("x1:5")
a=Wild("a")
b=Wild("b")
A=Wild('A', exclude=[0])
B=Wild('B', exclude=[0])
expr=f(x1,x2+x4,x3);
print("This one works")
print expr , '->' , expr.replace(f(a,Add(A,B),b),f(a,A,b)+f(a,B,b))
print("This one doesn't on the last entry")
expr=f(x1,x2,x3+x4);
print f(x1,x2,x3+x4) , '->' , expr.replace(f(a,Add(A,B),b),f(a,A,b)+f(a,B,b
))

I know I could iterate in a variety of ways over the arguments of the 
function while altering the replacement, but I was hoping the functionality 
was built into "Wild" or "replace" already. Mathematica, for example, has 
"wildcards" like "a___,b___,A___,B___" which mean that "a___" could be an 
empty sequence, or  a single argument, or a sequence of multiple arguments. 
Is there something similar, or is this is close as sympy gets?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/85b5fffd-2fff-4b0a-a7e8-4a81a9d90d57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to