如何强制 Mathematica 在 Simplify 和 FullSimplify 中包含用户定义的函数?

发布于 2024-11-05 18:10:42 字数 283 浏览 0 评论 0原文

假设我有一个关系 r^2 = x^2 + y^2。现在假设经过计算我得到了 x 和 y 的复杂输出,但理论上可以通过使用上述关系来简化很多。我如何告诉 Mathematica 这样做?

我指的是替换规则 x^2+y^2 -> 的情况r^2 和使用带有假设的 Simplify/FullSimplify 将不起作用,例如,如果输出为 x/y + y/x = (x^2+y^2)/(xy) = r^2/(xy)。

简化对于内置函数非常有效,但对于用户定义的函数却不起作用!所以本质上我希望我的函数被像内置函数一样对待!

Let's say I have a relation r^2 = x^2 + y^2. Now suppose after a calculation i get a complicated output of x and y, but which could in theory be simplified a lot by using the above relation. How do I tell Mathematica to do that?

I'm referring to situations where replacement rules x^2+y^2 -> r^2 and using Simplify/FullSimplify with Assumptions won't work, e.g. if the output is x/y + y/x = (x^2+y^2)/(xy) = r^2/(xy).

Simplification works really well with built in functions but not with user defined functions! So essentially I would like my functions to be treated like the built in functions!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

欲拥i 2024-11-12 18:10:42

我相信您正在寻找TransformationFunctions

f = # /. x^2 + y^2 -> r^2 &;

Simplify[x/y + y/x, TransformationFunctions -> {Automatic, f}]

(* Out=  r^2/(x y)  *)

I believe you are looking for TransformationFunctions.

f = # /. x^2 + y^2 -> r^2 &;

Simplify[x/y + y/x, TransformationFunctions -> {Automatic, f}]

(* Out=  r^2/(x y)  *)
天邊彩虹 2024-11-12 18:10:42

在你给出的例子中

(x/y + y/x // Together) /. {x^2 + y^2 -> r^2}

==> r^2/(x y)

。但我了解到,在很多情况下,这样的替代是行不通的。我曾经得到的一个提示是用一个更简单的 LHS 替换这个替代品,例如: x^2 -> r^2-y^2 (或者甚至是 x->Sqrt[r^2-y^2] 如果您知道 x 和 y 的值允许这样做)。

In the example you give

(x/y + y/x // Together) /. {x^2 + y^2 -> r^2}

==> r^2/(x y)

works. But I've learned that in many occasions replacements like this don't work. A tip I once got was to replace this replacement with one which has a more simpler LHS like: x^2 -> r^2-y^2 (or even x->Sqrt[r^2-y^2] if you know that the values of x and y allow this).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文