Hi all,
at first, I'd like to thank everyone who has put time into my problem.
As I have stated in some earlier posts, none of the solutions which had been proposed has worked for me because I had oversimplified the problem in my first post. The expressions in question are actually much more complex than those mentioned there.
In the meantime, I have come up with a solution which works for me. Since I think that my problem is a common one I would like to share this solution. The following is a transcript which won't require further explanation:
(%i1) my_expression: (((T02*T04*(1-K)^4))+(Z^2*(1+T02*T04)))^3;
2 4 3
(%o1) ((T02 T04 + 1) Z + (1 - K) T02 T04)
(%i2) HasFactor(expr):=(denom(expr/(T02*T04)) = 1)$
(%i3) matchdeclare(pattern, HasFactor)$
(%i4) defrule(r_Replace, pattern, T24*(pattern/(T02*T04)))$
(%i5) apply1(my_expression, r_Replace);
2 4 3
(%o5) ((T24 + 1) Z + (1 - K) T24)
(%i6)
That's the only way I could figure out for replacing a part of a product by another symbol. The method seems to work reliably: I have expressions with several hundreds of identical sub-products, and replacing these by new symbols worked for me using the method described above.
I did not test the method with fractions where the sub-products are in the numerator and denominator or other more complex situations.
Regards,
Peter
On 30.01.2013 19:08, Peter Pfannenschmid wrote:
> Hi all,
>
> I am new to Maxima (using it since yesterday), but thanks to the good documentation and many examples on the web, I could finish some tasks which were not too easy surprisingly fast. But in turn, I now can't find a solution for a very simple problem although I have put a significant amount of time into reading the manual and searching for examples.
>
> I am trying to replace parts of a product within an expression by another expression. For example, given the expression
>
> (i*j*k + i*k*l)^2,
>
> I would like to replace i*k by s, so that the expression becomes
>
> (s*j + s*l)^2.
>
> I have tried subst, but of course it did not work (i*k is not a complete subexpression in the example expression). Then I read a hint regarding ratsubst, but this does the wrong thing as well. Below is a transcription showing the problem:
>
> (%i7) test: (i*k*l + i*k*h)^2;
> 2
> (%o7) (i k l + h i k)
> (%i8) subst(s, (i*k), test);
> 2
> (%o8) (i k l + h i k)
> (%i9) ratsubst(s, (i*k), test);
> 2 2 2 2 2
> (%o9) l s + 2 h l s + h s
>
> Is there any way to achieve what I want?
>
> Thank you very much in advance,
>
> Peter