Question: How to find the factors when calling factor?

This is the context. I am doing reduction of order on an ODE. This sometimes converts the ode to form  where common factor containing only  x can be moved outside, making the ode looks like  f(x)*(y''(x)+....etc...) = 0 then now I can eliminate f(x)  and only solve (y''(x)+....etc...) = 0 which is simpler.

I found if I can call factor on the ode, it works. It does remove any common terms. The problem I am having is how to cleanly determine the factors obtained. In the above example, it will be f(x) and (y''(x)+....etc...) 

For an example, the ODE   x^2 y'' + x y' = 0 can be written (using factor) as  x ( x y'' + y') =0 and now canceling x<>0, the ode becomes simpler x y''+ y' = 0.

I am now trying to find the two factors, using using op() on the result of factor.

But it does not work for all cases. There should be a way more robust way to obtain the factors.  I give 2 examples to better explain.

Example 1

ode:=x^2*diff(y(x),x$2)-(x-3/16)*y(x)=0:
ode:=expand(algsubs( y(x)=v(x)*x^(1/4)*exp(2*sqrt(x)),ode));
ode:=factor(ode);

After factoring the original ODE, there is common term found, which is the one shown UP. I need to find this to cancel it and keep the rest.

Currently I do this, which does not work for call cases

#check it is factored OK. If the type is `*` then Maple
#found common factor.
if type(lhs(ode),`*`) then 
   #add code to extract the two parts
   LHS:=op([1..-2],lhs(ode));
   RHS:=op(-1,lhs(ode));
fi;

Even though this worked here. I can now check it is the LHS which needs to be canceled. But all what I have are the operands. I do not know how to reconstruct the LHS from the operands. They could be + or *.  If it was `*` between the oprands for LHS, then I can do LHS:=mul(LHS) and this gives 

But I got lucky here. I do not know if it will be `*` all the time for LHS operands.

example 2

ode:=x^2*diff(y(x),x$2)-x*(x+2)*diff(y(x),x)+(x+2)*y(x)=0;
ode:=algsubs( y(x)=v(x)*x,ode):
ode:=factor(ode);

For this, the code I have works, but this is only because the LHS was simple.

if type(lhs(ode),`*`) then #factored OK
   LHS:=op([1..-2],lhs(ode));
   RHS:=op(-1,lhs(ode));
fi;

My question is: I expect factor, if there is common factor, to generate 2 expressions with `*` between them. I am looking for a good way to find what these two factors are. Once I do, it is easy for me to find which is the ODE and which is not and cancel the one which is not out.

I tried collect, but this does not work in general. Since I do not know beforehand, what is the common term, if any, present.

If this needs more clarification please feel free to ask. I have many more examples. This is all done by coding. Non-interactive. So solution based on looking at the output then do something, will not work for me.

 

 

Please Wait...