Average Error: 34.2 → 9.8
Time: 2.0m
Precision: 64
Internal Precision: 3200
\[\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.7610052377381383 \cdot 10^{+36}:\\ \;\;\;\;\frac{\left(\left(-b\right) + \left(-b\right)\right) + \frac{c}{b} \cdot \left(a \cdot 2\right)}{a \cdot 2}\\ \mathbf{if}\;-b \le 3.764821240416611 \cdot 10^{-270}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{if}\;-b \le 6.983269397342713 \cdot 10^{+106}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.2
Target20.9
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 4 regimes
  2. if (- b) < -2.7610052377381383e+36

    1. Initial program 35.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 div-inv35.8

      \[\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}}\]
    4. Taylor expanded around inf 11.5

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

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

    if -2.7610052377381383e+36 < (- b) < 3.764821240416611e-270

    1. Initial program 10.9

      \[\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-num11.0

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

    if 3.764821240416611e-270 < (- b) < 6.983269397342713e+106

    1. Initial program 34.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 flip--34.8

      \[\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 simplify16.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 simplify16.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 6.983269397342713e+106 < (- b)

    1. Initial program 59.0

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.7610052377381383 \cdot 10^{+36}:\\ \;\;\;\;\frac{\left(\left(-b\right) + \left(-b\right)\right) + \frac{c}{b} \cdot \left(a \cdot 2\right)}{a \cdot 2}\\ \mathbf{if}\;-b \le 3.764821240416611 \cdot 10^{-270}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{if}\;-b \le 6.983269397342713 \cdot 10^{+106}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

herbie shell --seed '#(1070578969 3140398606 632207097 462683394 1189254563 964980650)' 
(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)))