Average Error: 33.9 → 10.9
Time: 2.2m
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 -3.8737124647248335 \cdot 10^{+59}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le -1.4333654669698449 \cdot 10^{+23}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{\left(-2\right) \cdot a}\\ \mathbf{if}\;b \le -4.028097694917915 \cdot 10^{-119}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.150885504737231 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{\left(-2\right) \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

  1. Inputs

  2. Original Output:

    Herbie Output:

Target

Original33.9
Target20.8
Herbie10.9
\[\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 < -3.8737124647248335e+59 or -1.4333654669698449e+23 < b < -4.028097694917915e-119

    1. Initial program 51.8

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

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

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

    if -3.8737124647248335e+59 < b < -1.4333654669698449e+23

    1. Initial program 47.2

      \[\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-2neg47.2

      \[\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 simplify47.2

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

    if -4.028097694917915e-119 < b < 2.150885504737231e+143

    1. Initial program 10.5

      \[\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.5

      \[\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.5

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

    if 2.150885504737231e+143 < b

    1. Initial program 56.9

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.8737124647248335 \cdot 10^{+59}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le -1.4333654669698449 \cdot 10^{+23}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{\left(-2\right) \cdot a}\\ \mathbf{if}\;b \le -4.028097694917915 \cdot 10^{-119}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.150885504737231 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}{\left(-2\right) \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' 
(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)))