ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Jul 2016 09:23:50 +0200Pattern matching in differential equationshttps://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/We have the following functional equation:
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)
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(.)?
Sun, 18 Aug 2013 11:04:58 +0200https://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/Comment by slelievre for <p>We have the following functional equation:
f(x<em>y)+f(x</em>(1-y))+f((1-x)<em>y)+f((1-x)</em>(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.</p>
<p>How can I change the occurences of the patterns to the appropriate g(.)?</p>
https://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/?comment=34149#post-id-34149@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?Wed, 20 Jul 2016 09:23:50 +0200https://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/?comment=34149#post-id-34149Answer by jupsal for <p>We have the following functional equation:
f(x<em>y)+f(x</em>(1-y))+f((1-x)<em>y)+f((1-x)</em>(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.</p>
<p>How can I change the occurences of the patterns to the appropriate g(.)?</p>
https://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/?answer=34137#post-id-34137 [Wildcards](http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/ring.html#sage.symbolic.ring.SymbolicRing.wild) 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. Tue, 19 Jul 2016 21:35:41 +0200https://ask.sagemath.org/question/10452/pattern-matching-in-differential-equations/?answer=34137#post-id-34137