# Problem in simplifying

I used below code to put terms in experesion which have k1^n (n>2) equal to zero. But it doesn't work properly because in answer there ae still terms with k1^n whch n>2. Does anyone know what is the problem? Another code by the help of the answer:

ham = 1/(dr e)
k1^2 ((0. + 1.4142135623730951 I) dc dr^2 e k1 Sqrt[-1. +
0.5 e ro] v +
C K (dr^2 e ro (2.000000000000001 -
1.0000000000000004 e ro) tr + (0. +
0.3535533905932738 I) k1 Sqrt[-1. + 0.5 e ro] v^2 xr +
dr ((-2.0000000000000004 + 0.5000000000000002 e ro) v xr +
k1 Sqrt[-1. +
0.5 e ro] (((0. +
3.535533905932738 I) - (0. +
0.8838834764831845 I) e ro) tr v +
d ((0. -
4.59619407771256 I) + (0. +
1.2374368670764584 I) e ro) xr))));
jovnv = Together[ham] //. k1^m_ /; m < 3 -> 0

• I think maybe there is a problem in this function in Mathematica. Maybe they have not pay attention to this problem! sigh... Apr 19, 2017 at 14:20
• There is nothing wrong in the output. In the given expression we can take k1^2 as common factor and since we have k1^m_ /; m < 3 -> 0 the whole expression becomes 0 Apr 20, 2017 at 10:42

## 2 Answers

Use ReplaceRepeated as you would need to get into deeper levels in the expression

experesion //. k1^n_ /; n > 2 -> 0


The output I get:

e k1 (dr e (dc k1 (dr^2 (1.36744*10^52 - 3.79203*10^42 e ro +
k1^2 (-6.83722*10^51 + 7.47847*10^11 e ro)) +
dr ((0. + 0. I) - (0. + 3.39416*10^28 I) k1) Sqrt[-1. +
0.5 e ro] v - 4.27327*10^50 k1^2 v^2) +
dr (3.79203*10^42 C K k1 ro tr +
v ((0. - 1.79944*10^50 I) dr Sqrt[-1. + 0.5 e ro] -
3.41861*10^51 k1 v))) +
d k1 (0. +
dr^3 e (-1.02558*10^52 + 1.61063*10^36 e ro +
k1^2 (5.98257*10^51 - 1.47487*10^32 e ro)) +
dr^2 e k1 (dc k1 (-11265. + 3.41861*10^51 e ro +
k1^2 (-3.06544*10^16 - 2.0298*10^51 e ro)) + ((0. -
1.35974*10^52 I) + (0. +
4.83465*10^51 I) k1^2) Sqrt[-1. + 0.5 e ro] v) +
dr k1 (e k1 (dc ((0. +
0. I) - (0. + 1.88853*10^51 I) k1) Sqrt[-1. +
0.5 e ro] - 1.8828*10^7 v) v +
C K (k1 (8.54653*10^50 + 6.54973*10^16 e ro) tr - (0. +
1.20866*10^51 I) Sqrt[-1. + 0.5 e ro] xr))))

• How many / should I use for a difficult case? is the number of /'s related to the number of parenthesis? Apr 19, 2017 at 10:07
• No. Please read the documentation for ReplaceRepeated. It says ReplaceRepeated repeatedly performs replacements until expr no longer changes. This is what is needed in your case. You can also use Cases to check what parts are matching the pattern. For Example: Cases[experesion, k^n_] gives empty list. This suggests that you go to deeper levels by using //. Apr 19, 2017 at 10:19
• Note also that Cases[experesion,k^n_,Infinity] gives a list of all the powers of k present in the expression. Apr 19, 2017 at 10:24
• I tried the code u suggest for another case, but it still works wrong. Plese run the code I added to the question Apr 19, 2017 at 10:34
• It worked as expected for your second expression also. Apr 19, 2017 at 10:39

For the second expression also we have:

In[13]:= expr1 =
e^2 (dr^3 (1.3674449212987683*^52 - 6.837224606493842^51 e ro +
k1^2 (-6.83722460649384*^51 + 1.7093061516234604^51 e ro)) +
dr^2 k1 (-6.83722460649384*^51 dc k1 +
d k1 (-1.196514306136422^52 + 3.4186123032469194*^51 e ro +
k1^2 (-2.1366326895293242^50 -
2.0298010550528586*^51 e ro)) + ((0. -
3.6259859128104894*^51 I) + (0. +
1.2086619709368297*^51 I) k1^2) Sqrt[-1. +
0.5 e ro] v) +
d k1^4 (d^2 k1^2 (-6.209588753944601^50 +
2.25347978973796*^50 e ro) - 8.01237258573497^49 v^2 +
d k1 (-2.403711775720491*^50 dc k1 - (0. +
2.2662411955065554*^50 I) Sqrt[-1. + 0.5 e ro] v)) +
dr k1^2 (d^2 k1^2 (-6.035987347920344^51 +
2.0832168722910918*^51 e ro +
k1^2 (2.0030931464337426^50 -
4.406804922154233*^50 e ro)) -
4.27326537905865*^50 v^2 +
d k1 (-2.5639592274351904*^51 dc k1 + ((0. -
1.8885343295887962*^51 I) + (0. +
2.266241195506556*^50 I) k1^2) Sqrt[-1. +
0.5 e ro] v)));

In[14]:= Together[expr1] //. k1^n_ /; n > 1 -> 0

Out[14]= 7.47847*10^11 e^2 ((0. + 0. I) + 1.82851*10^40 dr^3 -
5.0706*10^30 dr^3 e ro - (0. + 4.84857*10^39 I) dr^2 k1 Sqrt[-1. +
0.5 e ro] v)
`
• But there is a term dr^2 k1 (-6.83722*10^51 dc k1) which cantains k1^2 in your output Apr 19, 2017 at 10:40
• You must also try a few things. Try Together to combine the two k1's into k1^2 and then use //. Thst is Together[expr1] //. k1^n_ /; n > 1 -> 0 Apr 19, 2017 at 10:42
• I mean in term dr^2 k1 (-6.83722*10^51 dc k1) there is k1^2 which n is bigger than 1 Apr 19, 2017 at 10:42
• Still it dont work properly for some cases. Please chek the code I added Apr 19, 2017 at 12:26
• In the case I have added now, some terms are k1^3, but the output s zero Apr 19, 2017 at 12:27