Hi, I'm wondering what is going on here (ginsh output):
subs($1 * x + 1/2 * x^2 * $2, match(a * x + b, $1 + x * $2)); b*a+1/2*a^3
What happened to "x" ? The match by itself correctly finds
match(a * x + b, $1 + x * $2); {$2==a,$1==b}
but the substitution result is weird. Greetings, Jan
On Wed, 7 Jun 2017 18:26:47 +0200, Jan Rheinländer <jrheinlaender@gmx.de> said:
JR> Hi, I'm wondering what is going on here (ginsh output): >> subs($1 * x + 1/2 * x^2 * $2, match(a * x + b, $1 + x * $2)); JR> b*a+1/2*a^3 JR> What happened to "x" ? The match by itself correctly finds >> match(a * x + b, $1 + x * $2); JR> {$2==a,$1==b} JR> but the substitution result is weird. According to the GiNaC tutorial: "* A single wildcard matches any expression. " Thus, the wildcard $2 matches to x, then the expression $1 * $2 + 1/2 * $2^2 * $2 is substituted using {$2==a,$1==b}. -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
On Fri, 09 Jun 2017 16:58:37 +0100, "Vladimir V. Kisil" <kisilv@maths.leeds.ac.uk> said:
On Wed, 7 Jun 2017 18:26:47 +0200, Jan Rheinländer <jrheinlaender@gmx.de> said: JR> Hi, I'm wondering what is going on here (ginsh output):
>>> subs($1 * x + 1/2 * x^2 * $2, match(a * x + b, $1 + x * $2)); JR> b*a+1/2*a^3 JR> What happened to "x" ? The match by itself correctly finds The effect, which you are expecting, is achieved by by subs_options::no_pattern #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main(){ realsymbol x("x"), a("a"), b("b"); wildcard w0(0), w1(1); exmap repl; (a * x + b).match(w0 + x * w1,repl); cout << (w0 * x + pow(x,2) * w1 / 2).subs(repl,subs_options::no_pattern) << endl; // -> b*x+1/2*a*x^2 } -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
participants (2)
-
Jan Rheinländer
-
Vladimir V. Kisil