Average Error: 33.2 → 7.2
Time: 46.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 -2.45507471870279 \cdot 10^{+55}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.7042861197920702 \cdot 10^{-201}:\\ \;\;\;\;\left(\frac{2}{a} \cdot a\right) \cdot \frac{c}{\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 5.8982976860049175 \cdot 10^{+72}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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.2
Target20.7
Herbie7.2
\[\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 < -2.45507471870279e+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. Initial simplification56.4

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

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

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

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

    if -2.45507471870279e+55 < b < -2.7042861197920702e-201

    1. Initial program 33.7

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

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

      \[\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}\]
    5. Applied associate-/l/37.7

      \[\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)}}\]
    6. Simplified21.4

      \[\leadsto \frac{\color{blue}{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)}\]
    7. Using strategy rm
    8. Applied times-frac17.0

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

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

      \[\leadsto \frac{2}{a} \cdot \color{blue}{\frac{a \cdot c}{\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b}}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity17.0

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

      \[\leadsto \frac{2}{a} \cdot \color{blue}{\left(\frac{a}{1} \cdot \frac{c}{\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b}\right)}\]
    14. Applied associate-*r*7.7

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

    if -2.7042861197920702e-201 < b < 5.8982976860049175e+72

    1. Initial program 10.9

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

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

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

    if 5.8982976860049175e+72 < b

    1. Initial program 38.9

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied flip--60.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}\]
    5. Applied associate-/l/61.2

      \[\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)}}\]
    6. Simplified61.4

      \[\leadsto \frac{\color{blue}{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)}\]
    7. Using strategy rm
    8. Applied times-frac60.8

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.45507471870279 \cdot 10^{+55}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -2.7042861197920702 \cdot 10^{-201}:\\ \;\;\;\;\left(\frac{2}{a} \cdot a\right) \cdot \frac{c}{\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b}\\ \mathbf{elif}\;b \le 5.8982976860049175 \cdot 10^{+72}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 46.4s)Debug logProfile

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