Average Error: 33.2 → 8.2
Time: 2.3m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;-b \le -7.760265493027666 \cdot 10^{+144}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le 5.032398420968677 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}{\left(-2\right) \cdot a}\\ \mathbf{if}\;-b \le 2.4129553953665273 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.2
Target20.1
Herbie8.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if (- b) < -7.760265493027666e+144

    1. Initial program 57.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.2

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Applied simplify2.2

      \[\leadsto \color{blue}{\frac{-b}{a}}\]

    if -7.760265493027666e+144 < (- b) < 5.032398420968677e-131

    1. Initial program 10.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied frac-2neg10.0

      \[\leadsto \color{blue}{\frac{-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{-2 \cdot a}}\]
    4. Applied simplify10.0

      \[\leadsto \frac{\color{blue}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{-2 \cdot a}\]

    if 5.032398420968677e-131 < (- b) < 2.4129553953665273e+44

    1. Initial program 38.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip--38.4

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    4. Applied simplify15.5

      \[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Applied simplify15.5

      \[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}}}{2 \cdot a}\]

    if 2.4129553953665273e+44 < (- b)

    1. Initial program 56.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 42.9

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify4.3

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.2

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -7.760265493027666 \cdot 10^{+144}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le 5.032398420968677 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}{\left(-2\right) \cdot a}\\ \mathbf{if}\;-b \le 2.4129553953665273 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1072743783 989954326 4239155542 3782239461 3602631542 1719177920)' 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))