Average Error: 33.1 → 8.5
Time: 21.4s
Precision: 64
Internal Precision: 128
\[\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 -9.249965699304845 \cdot 10^{+55}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.844368114635892 \cdot 10^{-285}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le 4.966230851642398 \cdot 10^{+96}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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.1
Target20.4
Herbie8.5
\[\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 < -9.249965699304845e+55

    1. Initial program 56.4

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified3.6

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

    if -9.249965699304845e+55 < b < 8.844368114635892e-285

    1. Initial program 28.4

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

      \[\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 associate-/l/33.4

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified21.5

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*15.9

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

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

    if 8.844368114635892e-285 < b < 4.966230851642398e+96

    1. Initial program 8.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 div-inv9.0

      \[\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. Using strategy rm
    5. Applied un-div-inv8.9

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

    if 4.966230851642398e+96 < b

    1. Initial program 44.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.249965699304845 \cdot 10^{+55}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.844368114635892 \cdot 10^{-285}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{2 \cdot a}}{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le 4.966230851642398 \cdot 10^{+96}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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