Average Error: 33.3 → 9.1
Time: 2.9m
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.088079411572087 \cdot 10^{+73}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -5.719675338533628 \cdot 10^{-130}:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot 4}{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}} - b}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.4379711956110471 \cdot 10^{+51}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}{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.3
Target20.2
Herbie9.1
\[\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 < -6.088079411572087e+73

    1. Initial program 57.5

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

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

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

    if -6.088079411572087e+73 < b < -5.719675338533628e-130

    1. Initial program 39.3

      \[\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--39.4

      \[\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 simplify15.1

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

      \[\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}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt15.4

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

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

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

    if -5.719675338533628e-130 < b < 1.4379711956110471e+51

    1. Initial program 12.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 div-sub12.2

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

    if 1.4379711956110471e+51 < b

    1. Initial program 35.8

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -6.088079411572087 \cdot 10^{+73}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -5.719675338533628 \cdot 10^{-130}:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot 4}{\left|\sqrt[3]{b \cdot b - \left(4 \cdot a\right) \cdot c}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - \left(4 \cdot c\right) \cdot a}} - b}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.4379711956110471 \cdot 10^{+51}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.9m)Debug logProfile

herbie shell --seed 2018198 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

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