Average Error: 33.8 → 12.5
Time: 38.8s
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 -7.941202260299028 \cdot 10^{+130}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -2.9566148953587755 \cdot 10^{-99}:\\ \;\;\;\;\frac{a \cdot \left(4 \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\\ \mathbf{elif}\;b \le 1.0359194168322235 \cdot 10^{+82}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-\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.8
Target20.9
Herbie12.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 < -7.941202260299028e+130

    1. Initial program 60.3

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

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

    if -7.941202260299028e+130 < b < -2.9566148953587755e-99

    1. Initial program 43.5

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

      \[\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/45.8

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

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

    if -2.9566148953587755e-99 < b < 1.0359194168322235e+82

    1. Initial program 12.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity12.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}{2 \cdot a}\]
    4. Applied associate-/l*12.6

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    7. Using strategy rm
    8. Applied pow112.7

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

      \[\leadsto \frac{1}{\color{blue}{{\left(2 \cdot a\right)}^{1}} \cdot {\left(\frac{1}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\right)}^{1}}\]
    10. Applied pow-prod-down12.7

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

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

    if 1.0359194168322235e+82 < b

    1. Initial program 41.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 *-un-lft-identity41.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}{2 \cdot a}\]
    4. Applied associate-/l*41.8

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    5. Taylor expanded around 0 5.0

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    6. Simplified5.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.941202260299028 \cdot 10^{+130}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -2.9566148953587755 \cdot 10^{-99}:\\ \;\;\;\;\frac{a \cdot \left(4 \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\\ \mathbf{elif}\;b \le 1.0359194168322235 \cdot 10^{+82}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 38.8s)Debug logProfile

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