I need to extract all cubic roots from an expression (without manual selection). For example, it's easy to extract all quadratic roots this way:
f:=a-sqrt(a^2+b+(a+b^2)^(1/3))+(a-b^(1/3))^(1/3);
indets(f,sqrt);
But I'm not sure how to extract cubic roots directly. I did it this way:
ind:=indets(f,`^`);
{seq(`if`(op(2,ind[k])=1/3,ind[k],NULL),k=1..nops(ind))};
Is there an easier way?
You can get those using the indets command, by further qualifying the type of the exponent.
For example,
f:=a-sqrt(a^2+b+(a+b^2)^(1/3))+(a-b^(1/3))^(1/3):
indets(f,`^`(anything,1/3));
{b^(1/3), (a-b^(1/3))^(1/3), (b^2+a)^(1/3)}
indets(f,`^`(anything,1/2));
{(a^2+b+(b^2+a)^(1/3))^(1/2)}
Alternatively,
indets(f,anything^(1/3));
{b^(1/3), (a-b^(1/3))^(1/3), (b^2+a)^(1/3)}
indets(f,anything^(1/2));
{(a^2+b+(b^2+a)^(1/3))^(1/2)}