2
$\begingroup$

Say I have an expression which contains different product combination of very small variables, say, δA, δB, δC.

I want to set all the products and all the variables with exponents greater than 1 to 0; e.g.,

δA δB -> 0, δA δC -> 0, δA^2 -> 0, ... etc

I can do so by using replace command:

expression /. {δA δC -> 0, ...}

But that is definitely not the most efficient way. Can you give me any idea on how to make it happen without listing all the possibilities?

$\endgroup$
  • 1
    $\begingroup$ As ever, it's easiest to post a response when given a specific example, in proper code. Absent that, I'd suggest something like Normal[Series[expression/.Thread[vars->t*vars],{t,0,1}]]/.t->1. $\endgroup$ – Daniel Lichtblau Oct 6 '14 at 15:00
2
$\begingroup$

This is the most efficient I can think of:

With[{vars = (δA | δB | δC)},
     expr /. {x: vars * y: vars -> 0, vars^n_ /; n>1 -> 0}]
$\endgroup$
  • $\begingroup$ Thanks for reply! It seems to work for higher order terms but simply With[{vars = (δA | δB | δC)}, δA*δB/. {x: vars * y: vars -> 0, vars^n_ /; n>1 -> 0}] returns δA*δB $\endgroup$ – yuriyi Oct 6 '14 at 13:26
  • 1
    $\begingroup$ @YuriyIvanov I think parentheses are necessary here (x : vars) ( y : vars) $\endgroup$ – ybeltukov Oct 6 '14 at 13:29
  • $\begingroup$ @ybeltukov right, that is fine now. Thanks a lot! $\endgroup$ – yuriyi Oct 6 '14 at 13:33
  • $\begingroup$ @YuriyIvanov: Strange; for me (on Mathematica 8.0.0.0) the very expression you wrote (copy/pasted directly from your comment) evaluates to 0. $\endgroup$ – celtschk Oct 8 '14 at 9:44

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.