4

I'm getting a huge output, but it appears that almost every term should actually be zero, unless I'm misunderstanding the expression.

For example, part of the output reads

a (0.25 + 0. b) + b^2 (0. + 0./c) + b (-1. + 0. c) - 0.5 c + (b (-1. b - 0.5 c) c)/a^2

Simplify and FullSimplify won't get rid of these zero terms even with assumptions that a,b and c are real and non-zero. Suggestions ?

Sektor
  • 3,320
  • 7
  • 27
  • 36
Joe Comer
  • 41
  • 2

1 Answers1

4

To get what was said in the comments on record as an answer.

Chop is probably what you are looking for.

expr = 
  a (0.25 + 0. b) + b^2 (0. + 0./c) + b (-1. + 0. c) - 0.5 c + 
   (b (-1. b - 0.5 c) c)/a^2 // Chop
0.25 a - 1. b - 0.5 c + (b (-1. b - 0.5 c) c)/a^2

You might want to go further

expr = expr /. {1. x_ :> x, -1. x_ :> -x}
0.25 a - b - 0.5 c + (b (- b - 0.5 c) c)/a^2

Update

In general expressions with inexact coefficients can contain the forms 0.x, 1.x, and -1.x. None of these cause computation difficulties, but they are unattractive, and often we want to eliminate them.

With a help from Mr.Wizard, I offer the following pattern to do this task.

fixerPattern = u_ /; Sign[u] == u :> Sign[u] 

With this we can clean up

expr = 
  a (0.25 + 0. b) + b^2 (0. + 0./c) + 1.b (-1. + 0. c) - 0.5 c + 
    (b (-1. b - 0.5 c) c)/a^2

without using Chop and it takes care of the instances of both 1.b and -1.b.

expr /. fixerPattern

fixup

m_goldberg
  • 107,779
  • 16
  • 103
  • 257