Search code examples
maple

Get all cubic roots from an expression


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);

The result

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))};

The result

Is there an easier way?


Solution

  • 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)}