获取表达式的所有立方根

huangapple go评论88阅读模式
英文:

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

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?

答案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)}

huangapple
  • 本文由 发表于 2023年7月12日 23:03:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76672006.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定