Average Error: 33.9 → 8.6
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 -0.023046085366440986:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 1.8901979532421568 \cdot 10^{-305}:\\ \;\;\;\;\frac{\frac{a}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}} \cdot \frac{4 \cdot c}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.4399774592443239 \cdot 10^{+37}:\\ \;\;\;\;\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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.9
Target21.1
Herbie8.6
\[\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 < -0.023046085366440986

    1. Initial program 55.6

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

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

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

    if -0.023046085366440986 < b < 1.8901979532421568e-305

    1. Initial program 25.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 flip--25.1

      \[\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 simplify17.3

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot 4\right)}{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt17.5

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

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

    if 1.8901979532421568e-305 < b < 1.4399774592443239e+37

    1. Initial program 10.6

      \[\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-inv10.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}}\]

    if 1.4399774592443239e+37 < b

    1. Initial program 34.6

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -0.023046085366440986:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 1.8901979532421568 \cdot 10^{-305}:\\ \;\;\;\;\frac{\frac{a}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}} \cdot \frac{4 \cdot c}{\sqrt{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.4399774592443239 \cdot 10^{+37}:\\ \;\;\;\;\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}}\]

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed 2020178 
(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)))