# Question:why applyrule worked but not algsubs on this example

## Question:why applyrule worked but not algsubs on this example

Maple 2019

I never used applyrule before. Seems like a good command. I was trying to tell Maple to rewrite

as

I could not find one command to do it.  Collect does not work. The only way I figure to it, is by replacing

by a new single unused symbol, and then use collect on the symbol, then use subs again to replace the symbol with orginal  expression. like this

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2; #this is what I want to collect
applyrule(r=Z,expr);
collect(%,Z);
subs(Z=r,%)

In the above code, if I replace applyrule by algsubs, it does not work. Why?

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2;
algsubs(r=Z,expr);

You see, it did not replace (x^2-1)/x by Z, like applyrule does:

restart;
expr:=(x^2 - 1)/x^2*y + (x^2 - 1)/x^2;
r:=(x^2 - 1)/x^2;
applyrule(r=Z,expr);

I will learn applyrule now more to do this. I was just wondering why algsubs failed, and if applyrule is the better tool to do this. Or may be there is a better way to do this whole thing?

Maple 2019.1

﻿