5
$\begingroup$

It seems very simple question, I wish to get rid of the higher order by product of a*b. Any help is appreciated!

f = a^4 + 4 a^3 b + 6 a^2 b^2 + 4 a b^3 + b^4
f /. a b -> 0
(*output*)
a^4 + 4 a^3 b + 6 a^2 b^2 + 4 a b^3 + b^4
(*I want to have*)
a^4+b^4
$\endgroup$

3 Answers 3

4
$\begingroup$

Looking at FullForm, it seems this pattern will do it

pat0 = Times[_. , a | Power[a, _], b | Power[b, _]]

Examples:

f = a^4 + 4 a^3 b + 6 a^2 b^2 + 4 a b^3 + b^4;
f1 = 3 (a b - 2 c);
f2 = (a b - 2 c)/(c - a b)
DeleteCases[f, pat0, Infinity]
DeleteCases[f1, pat0, Infinity]
DeleteCases[f2, pat0, Infinity]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Thank you for the answer! Can I ask one more case? it works nicely with no denominator, but with it ,(a b - 2 c )/(c - a b), it does not work.How can I do it for the denominator? $\endgroup$
    – Saesun Kim
    Sep 3, 2016 at 22:31
  • $\begingroup$ @SaesunKim added option Infinity. This seems to work now on the new expression you added. Infinity tells it to keep searching for the pattern. $\endgroup$
    – Nasser
    Sep 3, 2016 at 23:17
  • $\begingroup$ Thank you so much. It is really amazing! I really appreciate your help :D $\endgroup$
    – Saesun Kim
    Sep 3, 2016 at 23:26
  • $\begingroup$ Wouldn't it be nice if your solution works on the equivalent expression f=(a + b)^4 ? $\endgroup$
    – yarchik
    Sep 4, 2016 at 17:36
  • $\begingroup$ @yarchik it will work, but need to expand first. This works: DeleteCases[Expand[(a + b)^4], pat0, Infinity] gives a^4+b^4. $\endgroup$
    – Nasser
    Sep 5, 2016 at 8:20
7
$\begingroup$

I would use an algebraic function for an algebraic operation, similar to what I did in the similar question, Replacement rules and algebra:

PolynomialMod[f, a b]
(*  a^4 + b^4  *)

Works with the rational function from a comment by the OP:

Block[{f = (a b - 2 c)/(c - a b)},
 PolynomialMod[f, a b]
 ]
(*  -2  *)
$\endgroup$
1
  • $\begingroup$ Thank you for introducing cool command! I can see that polynomialMod can be really useful! $\endgroup$
    – Saesun Kim
    Sep 5, 2016 at 17:36
6
$\begingroup$
 f /. a^(_:1) b^(_:1) :> 0

a^4 + b^4

$\endgroup$
1
  • $\begingroup$ (a + b)^4 /. a^(_ : 1) b^(_ : 1) :> 0 yields the same expression... $\endgroup$
    – yarchik
    Sep 4, 2016 at 17:37

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.