# method 'subs()'

Tatiana Zolo zolo at cs.unipr.it
Wed May 8 12:23:05 CEST 2002

```Hi all,
I don't understand the behavior of method 'subs()' in the following
case:

> subs(a^x*b^x, \$1^\$2*\$3^\$2==(\$1*\$3)^\$2);
(a*b)^x
> subs(a^5*b^5, \$1^\$2*\$3^\$2==(\$1*\$3)^\$2);
b^5*a^5

I also check it with a little program, that I attach, and the output is

Expression 1: b^x*a^x
List of match: {\$1==b,\$2==x,\$3==a}
Expression 1 after subs: (b*a)^x

Expression 2: b^5*a^5
List of match: {\$1==b,\$2==5,\$3==a}
Expression 2 after subs: b^5*a^5

Why is different the behavior of subs() when it is applied on
b^x*a^x or on b^5*a^5?

Best regards

Tatiana Zolo

-------------- next part --------------
#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;

typedef GiNaC::ex GExpr;
typedef GiNaC::symbol GSymbol;
typedef GiNaC::numeric GNumber;
typedef GiNaC::lst GList;

int main() {
GSymbol x("x");
GSymbol a("a");
GSymbol b("b");
GList l_1, l_2;

GExpr p = pow(a, x) * pow(b, x);
cout << endl << "Expression 1: " << p << endl;
match(p, pow(wild(1), wild(2)) * pow(wild(3), wild(2)), l_1);
cout << "List of match: " << l_1 << endl;
p = p.subs(pow(wild(1), wild(2)) * pow(wild(3), wild(2))
== pow(wild(1)*wild(3), wild(2)));
cout << "Expression 1 after subs: " << p << endl << endl;

GExpr q = pow(a, 5) * pow(b, 5);
cout << "Expression 2: " << q << endl;
match(q, pow(wild(1), wild(2)) * pow(wild(3), wild(2)), l_2);
cout << "List of match: " << l_2 << endl;
q = q.subs(pow(wild(1), wild(2)) * pow(wild(3), wild(2))
== pow(wild(1)*wild(3), wild(2)));
cout << "Expression 2 after subs: " << q << endl << endl;

return 0;
}
```