Average Error: 33.8 → 10.2
Time: 17.6s
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 -3.56950087216670373 \cdot 10^{75}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.36200651545441365 \cdot 10^{-75}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}}\\ \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 -3.56950087216670373 \cdot 10^{75}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r124862 = b;
        double r124863 = -r124862;
        double r124864 = r124862 * r124862;
        double r124865 = 4.0;
        double r124866 = a;
        double r124867 = r124865 * r124866;
        double r124868 = c;
        double r124869 = r124867 * r124868;
        double r124870 = r124864 - r124869;
        double r124871 = sqrt(r124870);
        double r124872 = r124863 + r124871;
        double r124873 = 2.0;
        double r124874 = r124873 * r124866;
        double r124875 = r124872 / r124874;
        return r124875;
}

double f(double a, double b, double c) {
        double r124876 = b;
        double r124877 = -3.5695008721667037e+75;
        bool r124878 = r124876 <= r124877;
        double r124879 = 1.0;
        double r124880 = c;
        double r124881 = r124880 / r124876;
        double r124882 = a;
        double r124883 = r124876 / r124882;
        double r124884 = r124881 - r124883;
        double r124885 = r124879 * r124884;
        double r124886 = 3.3620065154544137e-75;
        bool r124887 = r124876 <= r124886;
        double r124888 = 1.0;
        double r124889 = r124876 * r124876;
        double r124890 = 4.0;
        double r124891 = r124890 * r124882;
        double r124892 = r124891 * r124880;
        double r124893 = r124889 - r124892;
        double r124894 = sqrt(r124893);
        double r124895 = r124894 - r124876;
        double r124896 = 2.0;
        double r124897 = r124895 / r124896;
        double r124898 = r124882 / r124897;
        double r124899 = r124888 / r124898;
        double r124900 = -1.0;
        double r124901 = r124900 * r124881;
        double r124902 = r124887 ? r124899 : r124901;
        double r124903 = r124878 ? r124885 : r124902;
        return r124903;
}

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.8
Target21.2
Herbie10.2
\[\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 3 regimes
  2. if b < -3.5695008721667037e+75

    1. Initial program 42.1

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

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

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

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

    if -3.5695008721667037e+75 < b < 3.3620065154544137e-75

    1. Initial program 13.4

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

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

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

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

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

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

    if 3.3620065154544137e-75 < b

    1. Initial program 53.0

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

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

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

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

Reproduce

herbie shell --seed 2019195 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))