0
$\begingroup$

I have the following term:

term = (x AngleBracket[x (-x+Sum[v'[y[j]],j])])/AngleBracket[x^2]+Sum[v'[y[j]],j];
term //TeXForm

$\frac{x \left\langle x \left(\sum _j v'(y(j))-x\right)\right\rangle }{\left\langle x^2\right\rangle }+\sum _j v'(y(j))$

and want to apply Expand only to the part within the AngleBrackets. How can I do that?

The result for this simple example is supposed to be

(x AngleBracket[-x^2 + x Sum[v'[y[j]],j]])/AngleBracket[x^2] + Sum[v'[y[j]],j] //TeXForm

$\frac{x \left\langle x \sum _j v'(y(j))-x^2\right\rangle }{\left\langle x^2\right\rangle }+\sum _j v'(y(j))$

It is important to me that a solution should work for any example, no matter the depth of the expression etc.

$\endgroup$
  • $\begingroup$ does Replace[expr, AngleBracket[a_] :> AngleBracket[Expand[a]],All] give what you need? $\endgroup$ – kglr May 30 at 13:49
1
$\begingroup$

I like using Composition (@*) for this kind of thing:

term /. AngleBracket -> AngleBracket @* Expand //TeXForm

$\frac{x \left\langle x \sum _j v'(y(j))-x^2\right\rangle }{\left\langle x^2\right\rangle }+\sum _j v'(y(j))$

$\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.