Average Error: 33.1 → 9.8
Time: 2.4m
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 -6.606286567414996 \cdot 10^{-28}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 9.633104463257503 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \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.1
Target20.1
Herbie9.8
\[\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 3 regimes
  2. if b < -6.606286567414996e-28

    1. Initial program 54.7

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

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

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]

    if -6.606286567414996e-28 < b < 9.633104463257503e+103

    1. Initial program 13.7

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

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

    if 9.633104463257503e+103 < b

    1. Initial program 45.8

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

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

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify9.8

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -6.606286567414996 \cdot 10^{-28}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 9.633104463257503 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed 2018167 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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)))