Average Error: 33.4 → 11.5
Time: 1.2m
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.5869302652106472 \cdot 10^{+66}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 3.983337014248878 \cdot 10^{-109}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + \left(-b\right)\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\\ \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.4
Target20.2
Herbie11.5
\[\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 3 regimes
  2. if b < -1.5869302652106472e+66

    1. Initial program 37.1

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

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

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

    if -1.5869302652106472e+66 < b < 3.983337014248878e-109

    1. Initial program 12.7

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

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

    if 3.983337014248878e-109 < b

    1. Initial program 51.6

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.5869302652106472 \cdot 10^{+66}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 3.983337014248878 \cdot 10^{-109}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + \left(-b\right)\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) - \left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\\ \end{array}\]

Runtime

Time bar (total: 1.2m)Debug logProfile

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