Average Error: 33.6 → 10.0
Time: 2.3m
Precision: 64
Internal Precision: 3456
\[\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 -2.7055589360725797 \cdot 10^{-64}:\\ \;\;\;\;\frac{-c}{\frac{b}{1}}\\ \mathbf{if}\;b \le 3.419719012683224 \cdot 10^{+119}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.1
Herbie10.0
\[\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 < -2.7055589360725797e-64

    1. Initial program 53.0

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

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

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

    if -2.7055589360725797e-64 < b < 3.419719012683224e+119

    1. Initial program 13.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 div-inv13.1

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

    if 3.419719012683224e+119 < b

    1. Initial program 49.0

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify3.6

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1070706311 3771791028 4128836681 4194990999 2341756049 504035650)' +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)))