Average Error: 34.1 → 7.9
Time: 9.0s
Precision: 64
\[\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 -0.1973887031618163923063491438369965180755:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\ \mathbf{elif}\;b \le -7.171823963983999441512307744546786541929 \cdot 10^{-310}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.730494439370032074747470763239053019705 \cdot 10^{75}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{4}{\frac{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]
\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 -0.1973887031618163923063491438369965180755:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\

\mathbf{elif}\;b \le -7.171823963983999441512307744546786541929 \cdot 10^{-310}:\\
\;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\

\mathbf{elif}\;b \le 2.730494439370032074747470763239053019705 \cdot 10^{75}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{4}{\frac{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{c}}\\

\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\end{array}
double f(double a, double b, double c) {
        double r130768 = b;
        double r130769 = -r130768;
        double r130770 = r130768 * r130768;
        double r130771 = 4.0;
        double r130772 = a;
        double r130773 = r130771 * r130772;
        double r130774 = c;
        double r130775 = r130773 * r130774;
        double r130776 = r130770 - r130775;
        double r130777 = sqrt(r130776);
        double r130778 = r130769 + r130777;
        double r130779 = 2.0;
        double r130780 = r130779 * r130772;
        double r130781 = r130778 / r130780;
        return r130781;
}

double f(double a, double b, double c) {
        double r130782 = b;
        double r130783 = -0.1973887031618164;
        bool r130784 = r130782 <= r130783;
        double r130785 = 1.0;
        double r130786 = 2.0;
        double r130787 = r130785 / r130786;
        double r130788 = c;
        double r130789 = r130788 / r130782;
        double r130790 = a;
        double r130791 = r130782 / r130790;
        double r130792 = r130789 - r130791;
        double r130793 = r130786 * r130792;
        double r130794 = r130787 * r130793;
        double r130795 = -7.171823963984e-310;
        bool r130796 = r130782 <= r130795;
        double r130797 = -r130782;
        double r130798 = r130782 * r130782;
        double r130799 = 4.0;
        double r130800 = r130799 * r130790;
        double r130801 = r130800 * r130788;
        double r130802 = r130798 - r130801;
        double r130803 = sqrt(r130802);
        double r130804 = r130797 + r130803;
        double r130805 = r130786 * r130790;
        double r130806 = r130785 / r130805;
        double r130807 = r130804 * r130806;
        double r130808 = 2.730494439370032e+75;
        bool r130809 = r130782 <= r130808;
        double r130810 = r130797 - r130803;
        double r130811 = r130785 * r130810;
        double r130812 = r130811 / r130788;
        double r130813 = r130799 / r130812;
        double r130814 = r130787 * r130813;
        double r130815 = -1.0;
        double r130816 = r130815 * r130789;
        double r130817 = r130809 ? r130814 : r130816;
        double r130818 = r130796 ? r130807 : r130817;
        double r130819 = r130784 ? r130794 : r130818;
        return r130819;
}

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

Original34.1
Target21.4
Herbie7.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -0.1973887031618164

    1. Initial program 32.2

      \[\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-+59.4

      \[\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. Simplified58.8

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

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity58.8

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)}\]
    16. Simplified8.0

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

    if -0.1973887031618164 < b < -7.171823963984e-310

    1. Initial program 10.9

      \[\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-inv11.1

      \[\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 -7.171823963984e-310 < b < 2.730494439370032e+75

    1. Initial program 30.4

      \[\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-+30.4

      \[\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. Simplified16.7

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

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity16.7

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

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

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

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

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

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

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

    if 2.730494439370032e+75 < b

    1. Initial program 58.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -0.1973887031618163923063491438369965180755:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\right)\\ \mathbf{elif}\;b \le -7.171823963983999441512307744546786541929 \cdot 10^{-310}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.730494439370032074747470763239053019705 \cdot 10^{75}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{4}{\frac{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0.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)))