Average Error: 33.7 → 8.3
Time: 1.3m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.3338600865169524 \cdot 10^{+85}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -1.3407597897048622 \cdot 10^{-276}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.5801122062859315 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot \left(-c\right)}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot \left(-c\right)}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right) + b}\\ \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.7
Target21.0
Herbie8.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.3338600865169524e+85

    1. Initial program 42.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification42.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified3.9

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

    if -1.3338600865169524e+85 < b < -1.3407597897048622e-276

    1. Initial program 9.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification9.3

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-inv9.4

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

    if -1.3407597897048622e-276 < b < 4.5801122062859315e+86

    1. Initial program 31.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification31.3

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied flip--31.4

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

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

      \[\leadsto \frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    7. Using strategy rm
    8. Applied distribute-lft-neg-out22.0

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

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

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

    if 4.5801122062859315e+86 < b

    1. Initial program 58.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification58.1

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied flip--58.1

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

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

      \[\leadsto \frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    7. Using strategy rm
    8. Applied distribute-lft-neg-out31.0

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

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

      \[\leadsto -\color{blue}{\frac{c \cdot \frac{4}{\frac{2}{1}}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b}}\]
    11. Taylor expanded around inf 7.7

      \[\leadsto -\frac{c \cdot \frac{4}{\frac{2}{1}}}{\color{blue}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right)} + b}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3338600865169524 \cdot 10^{+85}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -1.3407597897048622 \cdot 10^{-276}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.5801122062859315 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot \left(-c\right)}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot \left(-c\right)}{\left(b - 2 \cdot \frac{a \cdot c}{b}\right) + b}\\ \end{array}\]

Runtime

Time bar (total: 1.3m)Debug logProfile

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

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))