Average Error: 33.3 → 6.9
Time: 2.2m
Precision: 64
Internal Precision: 3136
\[\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.263114766361561 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.123125416596865 \cdot 10^{-212}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} \cdot \sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.7499400189058717 \cdot 10^{+146}:\\ \;\;\;\;\left(\sqrt[3]{-2 \cdot c} \cdot \sqrt[3]{-2 \cdot c}\right) \cdot \frac{\sqrt[3]{-2 \cdot c}}{b + \sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{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.3
Target20.7
Herbie6.9
\[\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.263114766361561e+105

    1. Initial program 45.7

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

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

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

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

    if -1.263114766361561e+105 < b < 9.123125416596865e-212

    1. Initial program 10.2

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

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

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

    if 9.123125416596865e-212 < b < 3.7499400189058717e+146

    1. Initial program 37.4

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

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

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

      \[\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}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/37.5

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

      \[\leadsto \frac{\color{blue}{\frac{-4 \cdot \left(c \cdot a\right) + 0}{\frac{a}{\frac{1}{2}}}}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity14.5

      \[\leadsto \frac{\frac{-4 \cdot \left(c \cdot a\right) + 0}{\frac{a}{\frac{1}{2}}}}{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}}\]
    11. Applied add-cube-cbrt15.3

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

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

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

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

    if 3.7499400189058717e+146 < b

    1. Initial program 62.0

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.263114766361561 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.123125416596865 \cdot 10^{-212}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} \cdot \sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.7499400189058717 \cdot 10^{+146}:\\ \;\;\;\;\left(\sqrt[3]{-2 \cdot c} \cdot \sqrt[3]{-2 \cdot c}\right) \cdot \frac{\sqrt[3]{-2 \cdot c}}{b + \sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 2.2m)Debug logProfile

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