5
$\begingroup$

I want to cut off terms starting with higher order than epsilon^0. It works fine for any other value but unfortunately, I need to truncate values with higher order than 0 or 1. But it seems not to work. I made a simplified example below.

eq1 = ϵ^-2*x + ϵ^-1*
       x + ϵ^0 x + ϵ^1*x + ϵ^2*
        x + ϵ^3*x + ϵ^4*x + ϵ^5*x;

eq2 = eq1 /. ϵ^b_ /; b >=  3 -> 0
eq3 = eq1 /. ϵ^b_ /; b >= 1 -> 0
eq4 = eq1 /. ϵ^b_ /; b > 1 -> 0
eq5 = eq1 /. ϵ^b_ /; b >=  0 -> 0
eq6 = eq1 /. ϵ^b_ /; b >  0 -> 0

Which gives me the following output:

enter image description here

It can be seen from the output that the code works perfectly if I want to remove terms with a higher order than 1 (see eq2). But it doesn't remove terms with an order of 0 or 1. If anybody could tell me what to do to make it possible to remove terms with an order of 1 as well that would be great. Thank you.

$\endgroup$
1
  • 5
    $\begingroup$ Why not use Series and Normal? $\endgroup$
    – Carl Woll
    Commented Feb 10, 2021 at 17:31

2 Answers 2

7
$\begingroup$

As Carl Woll suggested, you can use Series to do this for you. Normal will then generate a truncated output:

Normal@ Series[eq1, {ϵ, 0, 2}]
(* Out: x + x/ϵ^2 + x/ϵ + x ϵ + x ϵ^2 *)

Normal@ Series[eq1, {ϵ, 0, 1}]
(* Out: x + x/ϵ^2 + x/ϵ + x ϵ *)

Normal@ Series[eq1, {ϵ, 0, 0}]
(* Out: x + x/ϵ^2 + x/ϵ *)
$\endgroup$
3
$\begingroup$

This is because the atomic expression of n*x is not in the form of Power:

ϵ*x // FullForm
x // FullForm
ϵ^-1*x // FullForm

So the Power pattern cannot match the Times pattern. And we can delete the first power term of ϵ by adding rules:

eq2 = eq1 //. {Times[__, Power[ϵ, a_] /; a >= 3 || a < 0] -> 
    0, Power[ϵ, b_] /; b >= 3 || b < 0 -> 0}

It is more troublesome to eliminate the zero power term of ϵ. I haven't found a good way to eliminate it yet.

StringContainsQ[ToString[FullForm[eq1]], "Epsilon"]
$\endgroup$

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