如何在 Mathematica 中替换函数和完全简化? [英] How to substitute functions and Full Simplify in Mathematica?

查看:108
本文介绍了如何在 Mathematica 中替换函数和完全简化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下函数 -((A N1 P (AB k (a N1 + aa P - r) + a aa (b B - bb) k R + 2 AB r R)))/k)-- (1)

这个函数可以改写为:- A R P N1 d/k --- (2)

哪里:

R 是 (k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r)P 是 (-a^2 b k mm - A B m r +a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r))N1 是 (-aa^2 bb k m + A mm r +aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r))d 是 aaa (b B - bb) k + A B r

如何在 (1) 中进行这些替换以到达 Mathematica 中的 (2)?

我在d"的编码中犯了一个小错误.我现在已经编辑了等式.

根据建议,我已经评估了 (1) 和 (2) 中的两个表达式,以确保其大小相等.

{a, A, aa, b, B, bb, k, m, mm, r} = RandomReal[{0, 20}, 10];R = (k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r);P = (-a^2 b k mm - A B m r +a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r));N1 = (-aa^2 bb k m + A mm r +aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r));d = a aa (b B - bb) k + A B r;{-((A N1 P (A B k (a N1 + aa P - r) + a aa (b B - bb) k R +2 A B r R)))/k), -A R P N1 d/k}{-39976.5, -39976.5}

解决方案

我不能保证以下工作流会普遍成功,但在这里工作得很好.它结合了三个想法:(1)多项式代数更接近一个好的结果;(2) 代入扩大变量;(3) 崩溃"将变量(项")组合成单个变量.


设置

从建立输入开始: variables 只是一个原子变量名的列表;terms 是要展开的值的列表 RPN1d进入;而 x 是原始多项式.

variables = {a, aa, b, bb, d, k, mm, r, A, B, R, P, N1};项 = {(k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r),(-a^2 b k mm - A B m r + a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r)),(-aa^2 bb k m + A mm r + aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r)),a aa (b B - bb) k + A B r};x = ((A N1 P (A B k (a N1 + aa P - r) + a aa (b B - bb) k R + 2 A B r R))/k);

根据这些信息我们可以为术语构建一个替换规则列表.这些将执行替换步骤.

rules = (Rule @@#) &/@转置[{{R, P, N1, d},terms}]

例如,Rules 的第四个组成部分是

<块引用>

d ->a aa (b B - bb) k + A B r

和前三个组件分别是 RPN1 的可比较表达式.

分析

PolynomialReduce 为我们提供了将 x 表示为 terms 的(有理的)线性组合加上可能出现的任何余数的第一次破解.

{部分,余数} = PolynomialReduce[x,项,变量]

<块引用>

{{0, 0, 0, (A N1 PR)/k}, a A^2 B N1^2 P + A^2 aa B N1 P^2 - A^2 B N1 P r + (A^2 B N1 P r R)/k}

第一部分,parts,包含系数{0, 0, 0, (A N1 PR)/k}:前三项的系数是零和最后一项的系数(最终将表示为d)是A N1 PR/k,因此结果是x 已展开为线性组合 0(R) + 0(P) + 0(N1) + (A N1 PR/k) d 加上余数.

我们已经取得了进展,但现在是处理剩余部分的时候了.为此,应用替换规则:Simplify[remainder/.规则].要重新创建 x,需要将此余数添加到前面的线性组合中.让我们一次性完成:

部分.规则 [[;;, 1]] + 简化[余数/.规则]

<块引用>

(A d N1 P R)/k

注意在rules中使用target模式是如何将a aa (b B - bb) k + AB r隐式折叠成>d 而规则本身将余数简化为 0.一般来说余数不会那么简单——但至少它可能比你开始时更简单.


结束评论

我相信这种代数表达式的一般操作是为了将一种形式扭曲成另一种简单"的形式.在某种意义上是一个 NP-hard 问题,所以 YMMV.我的经验是,您必须尝试简化复杂的表达式,并用自己的代数技能以及对简化形式可能采取的形式的感觉来增强它.

I have the following function -((A N1 P (A B k (a N1 + aa P - r) + a aa (b B - bb) k R + 2 A B r R))/k) -- (1)

This function can be rewritten as: - A R P N1 d/k --- (2)

where:

R is (k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r)

P is (-a^2 b k mm - A B m r + 
 a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r))

N1 is (-aa^2 bb k m + A mm r + 
 aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r))

d is a aa (b B - bb) k + A B r

How can I make these substitutions in (1) to arrive at (2) in Mathematica?

Edit: I had made a small error in the coding for "d". I have edited the equation now.

As per suggestion, I have evaluated both expressions in (1) and (2) to ensure that it is of equal magnitude.

{a, A, aa, b, B, bb, k, m, mm, r} = RandomReal[{0, 20}, 10];
R = (k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r);
P = (-a^2 b k mm - A B m r + 
     a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r));
N1 = (-aa^2 bb k m + A mm r + 
     aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r));
d = a aa (b B - bb) k + A B r;
{-((A N1 P (A B k (a N1 + aa P - r) + a aa (b B - bb) k R + 
        2 A B r R))/k), -A R P N1 d/k}
{-39976.5, -39976.5}

解决方案

I can't guarantee the following workflow will succeed universally, but it works well here. It combines three ideas: (1) polynomial algebra to get closer to a nice result; (2) substitution to expand the variables; and (3) "collapsing" combinations of the variables ("terms") into single variables.


The setup

Begin by establishing the input: variables is just a list of the atomic variable names; terms is a list of the values to expand R, P, N1, and d into; and x is the original polynomial.

variables = {a, aa, b, bb, d, k, mm, r, A, B, R, P, N1};
terms = {(k (aa B m - a mm + A B r))/(a aa (b B - bb) k + A B r), 
         (-a^2 b k mm - A B m r + a k (aa bb m + A b B r))/(A (a aa (b B - bb) k + A B r)),
         (-aa^2 bb k m + A mm r +  aa k (a b mm - A bb r))/(A (a aa (b B - bb) k + A B r)), 
         a aa (b B - bb) k + A B r};
x = ((A N1 P (A B k (a N1 + aa P - r) + a aa (b B - bb) k R + 2 A B r R))/k);

From this information we can construct a list of replacement rules for the terms. These will carry out the substitution step.

rules = (Rule @@ #) & /@ Transpose[{{R, P, N1, d}, terms}]

For instance, the fourth component of Rules is

d -> a aa (b B - bb) k + A B r

and the first three components are comparable expressions for R, P, and N1, respectively.

The analysis

PolynomialReduce gives us a first crack at expressing x as a (rational) linear combination of terms plus any remainder that might fall out.

{parts, remainder} = PolynomialReduce[x, terms, variables]

{{0, 0, 0, (A N1 P R)/k}, a A^2 B N1^2 P + A^2 aa B N1 P^2 - A^2 B N1 P r + (A^2 B N1 P r R)/k}

The first piece, parts, contains the coefficients {0, 0, 0, (A N1 P R)/k}: the coefficients of the first three terms are zero and the coefficient of the last term (which eventually will be expressed as d) is A N1 P R/k, whence the result is that x has been expanded into the linear combination 0(R) + 0(P) + 0(N1) + (A N1 P R/k) d plus the remainder.

We have already made progress, but now it's time to work with the remainder. To do so, apply the substitution rules: Simplify[remainder /. rules]. To recreate x, this remainder needs to be added to the preceding linear combination. Let's do it all at once:

parts . rules [[;; , 1]] + Simplify[remainder /. rules]

(A d N1 P R)/k

Notice how using the target patterns in rules has implicitly collapsed a aa (b B - bb) k + A B r into d while the rules themselves simplified the remainder to 0. In general the remainder won't get that simple--but at least it's likely to be simpler than what you started with.


Closing comments

I believe that general manipulation of such algebraic expressions in an effort to twist one form into another that is "simple" in some sense is an NP-hard problem, so YMMV. My experience is that you have to experiment with simplifying complex expressions and augment that with your own algebraic skills as well as your sense of what form the simplification is likely to take.

这篇关于如何在 Mathematica 中替换函数和完全简化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆