1
$\begingroup$

When your input is 1 + x^2 + x^3 /. x^2 -> 0, you get 1 + x^3. What should you type in to get 1?

$\endgroup$
4
  • 3
    $\begingroup$ That's a tricky question because 1 + x^2 + x^3 /. _ -> 1 does that. $\endgroup$
    – Kuba
    Aug 27, 2016 at 20:39
  • $\begingroup$ 1 + x^2 + x^3 /. {x^2 -> 0, x^3 -> 0} $\endgroup$ Aug 27, 2016 at 20:39
  • 1
    $\begingroup$ expr = 1 + x^2 + x^3; expr /. First@Solve[expr == 1, x] gives 1 :) $\endgroup$
    – Nasser
    Aug 27, 2016 at 21:15
  • 1
    $\begingroup$ 1 + x^2 + x^3 /. x -> 0 $\endgroup$
    – Bob Hanlon
    Aug 27, 2016 at 21:18

3 Answers 3

3
$\begingroup$

With respect to a comment that should be incorporated into the question, there is PolynomialMod:

PolynomialMod[
 a + b x + c y + d z + e x^2 + f x^2 y + g z^2 + h x^3 z + k x y z + l x^2 y^2 z^2,
 x^2]
(*  a + b x + c y + d z + k x y z + g z^2  *)

One could use a replacement rule, too:

a + b x + c y + d z + e x^2 + f x^2 y + g z^2 + h x^3 z + k x y z + 
  l x^2 y^2 z^2 /. x^p_Integer /; p > 1 -> 0
(*  a + b x + c y + d z + k x y z + g z^2  *)

As for most of what's posted right now, I think everyone but Bob is pulling your leg a little:

1 + x^2 + x^3 /. x -> 0 – Bob Hanlon 40 mins ago

But this will set all the terms with a factor of x to the first power to zero, too, which fits with the original question but not the comment.

The thing to keep in mind about replacement rules is that whatever subexpression matches the pattern on the left-hand is replaced by the corresponding expression on the left-hand side. As expression-tree transformations, they sometimes do not behave quite like the algebra transformations one might be used to. For instance, you cannot replace the factor of x^2 in x^3, because as an expression, x^3 does not contain x^2, just Power[x, 3]. There's no 2 and certainly not Power[x, 2]. What's more troublesome is that x^2 * x automatically becomes x^3 inside Mathematica, unless you do some fancy things to interfere with the normal evaluation of expressions.

The point is that sometimes there are functions like PolynomialMod[] that are more appropriate for doing algebra than replacement rules.

$\endgroup$
0
$\begingroup$

One way is to use a variable in the argument of the index:

1 + x^2 + x^3 /. x^i_ -> 0
$\endgroup$
2
  • 1
    $\begingroup$ i_. will help with x too. $\endgroup$
    – Kuba
    Aug 27, 2016 at 20:40
  • 1
    $\begingroup$ No way of using the fact that x^3is a multiple of x^2? Imagine I want to get rid of any monomial that contains x^2 in a polynomial in three variables like a + b x + c y + d z + e x^2 + f x^2 y + g z^2 + h x^3 z + k x y z + l x^2 y^2 z^2. Mathematica can surely do that. $\endgroup$ Aug 27, 2016 at 21:00
0
$\begingroup$

I think that what you are looking for is first order series expansion wrt x

1 + x^2 + x^3;
% + O[x]^2 
(*1 + O[x]^2*)

a + b x + c y + d z + e x^2 + f x^2 y + g z^2 + h x^3 z + k x y z + l x^2^2 z^2;
% + O[x]^2
(*(a + c y + d z + g z^2) + (b + k y z) x + O[x]^2 *)

The O[x]^2 (conversion from SeriesData) can be eliminated by applying Normal.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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