英文:
Get all cubic roots from an expression
问题
我需要从表达式中提取所有的立方根(无需手动选择)。
例如,可以通过以下方式轻松提取所有二次根:
f:=a-sqrt(a^2+b+(a+b^2)^(1/3))+(a-b^(1/3))^(1/3);
indets(f,sqrt);
但我不确定如何直接提取立方根。我是这样做的:
ind:=indets(f,`^`);
{seq(`if`(op(2,ind[k])=1/3,ind[k],NULL),k=1..nops(ind))};
有更简单的方法吗?
英文:
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?
答案1
得分: 2
你可以使用indets命令来获取这些指数的内容,进一步限定指数的类型。
例如,
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)}
或者,
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)}
英文:
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)}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论