# Pattern matching in differential equations This post is a wiki. Anyone with karma >750 is welcome to improve it.

We have the following functional equation: f(xy)+f(x(1-y))+f((1-x)y)+f((1-x)(1-y)) == f(x)+f(1-x)+f(y)+f(1-y) Differentiating by x then y we get a second order differential equation which contains the pattern g(t)=f'(t)+tf''(t) three times with different expressions for t.

How can I change the occurences of the patterns to the appropriate g(.)?

edit retag close merge delete

@czsan: To display inline code, surround it within backticks .

To display blocks of code, either indent them with 4 spaces, or select the corresponding lines and click the "code" button (the icon with '101 010'). Can you edit your question to do that?

Sort by » oldest newest most voted

Wildcards might help you here. For instance, I got this (not ideal) way to produce what you want:

x,y,t = var('x,y,t')
f = function('f'); g = function('g')
w0 = SR.wild(0); w1 = SR.wild(1)
pattern1 = w0*f(t).diff(t,2)(t = w0); pattern2 = w0*f(t).diff(t,2)(t = -w0)
eqn = f(x*y) + f(x*(1-y)) + f((1-x)*y) + f((1-x)*(1-y)) - f(x) - f(1-x) - f(y) -f(1-y)
eqn2d = eqn.diff(x,y)
eqn2d.subs( pattern1 == g(w0) - f(t).diff(t)(t=w0), pattern2 == g(-w0) + f(t).diff(t)(t=-w0) )


Now obviously it would be nice if Sage could just notice that pattern1 is related to pattern2, but I couldn't get it to work out (maybe someone better at Sage can?). It is worth noting that I also tried using

pattern = f(t).diff(t)(t = w0) + w0*f(t).diff(t,2)(t = w0)


but eqn2d seems to have no occurrences of that pattern: eqn2d.has(pattern) returns False`. I would be curious to see if anyone has an explanation for this as well.

more