3
$\begingroup$

I have very large analytical expressions that are averaged "Mean[...]" and I would like to simpify as much as possible. The issue is that although Mathematica recognizes the commutative property:

Mean[a*b]-Mean[b*a]=0

Its does not recognize distributive property:

Mean[a+b]-Mean[a]-Mean[b] =/= 0

I was wondering if anyone knows of a way to implement this distributive property? For example, have Mathematica recognize that:

Mean[a+b]-Mean[a]-Mean[b] = 0

Like I said I have expressions that are extremely long and would love to be able to just have Mathematica take the average and then Simplify[...] for me.

$\endgroup$
  • $\begingroup$ You could write your own rule: Mean[a - b] - Mean[a] + Mean[b] //. {Mean[x_ + y_] -> Mean[x] + Mean[y], Mean[-x_] -> -Mean[x]}. (The second rule is needed as there might be subtraction for some cases.) $\endgroup$ – JimB Oct 7 '16 at 1:00
2
$\begingroup$

Just to expand on Jim's comment:

Mean[a + b - c] - Mean[a] + Mean[-b] - Mean[-c] //. {
    Mean[Plus[a_, addends__]] :> Mean[a] + Mean[Plus[addends]],
    Mean[-a_] :> -Mean[a]
    }

yields 0.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.