Average Error: 33.5 → 8.7
Time: 41.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 -6.376253530740768 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.2059736638617364 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{elif}\;b \le 8.834167001137509 \cdot 10^{-10}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\frac{a}{\frac{1}{2}}} \cdot \frac{-1}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;\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 -6.376253530740768 \cdot 10^{+152}:\\
\;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r9242851 = b;
        double r9242852 = -r9242851;
        double r9242853 = r9242851 * r9242851;
        double r9242854 = 4.0;
        double r9242855 = a;
        double r9242856 = r9242854 * r9242855;
        double r9242857 = c;
        double r9242858 = r9242856 * r9242857;
        double r9242859 = r9242853 - r9242858;
        double r9242860 = sqrt(r9242859);
        double r9242861 = r9242852 + r9242860;
        double r9242862 = 2.0;
        double r9242863 = r9242862 * r9242855;
        double r9242864 = r9242861 / r9242863;
        return r9242864;
}

double f(double a, double b, double c) {
        double r9242865 = b;
        double r9242866 = -6.376253530740768e+152;
        bool r9242867 = r9242865 <= r9242866;
        double r9242868 = a;
        double r9242869 = c;
        double r9242870 = r9242869 / r9242865;
        double r9242871 = r9242868 * r9242870;
        double r9242872 = r9242871 - r9242865;
        double r9242873 = 2.0;
        double r9242874 = r9242872 * r9242873;
        double r9242875 = r9242873 * r9242868;
        double r9242876 = r9242874 / r9242875;
        double r9242877 = 3.2059736638617364e-150;
        bool r9242878 = r9242865 <= r9242877;
        double r9242879 = 0.5;
        double r9242880 = r9242865 * r9242865;
        double r9242881 = 4.0;
        double r9242882 = r9242868 * r9242869;
        double r9242883 = r9242881 * r9242882;
        double r9242884 = r9242880 - r9242883;
        double r9242885 = sqrt(r9242884);
        double r9242886 = r9242885 - r9242865;
        double r9242887 = r9242886 / r9242868;
        double r9242888 = r9242879 * r9242887;
        double r9242889 = 8.834167001137509e-10;
        bool r9242890 = r9242865 <= r9242889;
        double r9242891 = r9242868 / r9242879;
        double r9242892 = r9242883 / r9242891;
        double r9242893 = -1.0;
        double r9242894 = r9242865 + r9242885;
        double r9242895 = r9242893 / r9242894;
        double r9242896 = r9242892 * r9242895;
        double r9242897 = -r9242869;
        double r9242898 = r9242897 / r9242865;
        double r9242899 = r9242890 ? r9242896 : r9242898;
        double r9242900 = r9242878 ? r9242888 : r9242899;
        double r9242901 = r9242867 ? r9242876 : r9242900;
        return r9242901;
}

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.5
Target20.4
Herbie8.7
\[\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 < -6.376253530740768e+152

    1. Initial program 60.5

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    4. Simplified2.0

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

    if -6.376253530740768e+152 < b < 3.2059736638617364e-150

    1. Initial program 10.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num10.6

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    8. Applied add-sqr-sqrt10.6

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

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

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

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

    if 3.2059736638617364e-150 < b < 8.834167001137509e-10

    1. Initial program 32.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num32.1

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}\]
    7. Applied associate-/r/32.2

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

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\frac{2 \cdot a}{\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} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    9. Applied times-frac32.3

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

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

    if 8.834167001137509e-10 < b

    1. Initial program 54.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified6.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.376253530740768 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.2059736638617364 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{elif}\;b \le 8.834167001137509 \cdot 10^{-10}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\frac{a}{\frac{1}{2}}} \cdot \frac{-1}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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