Average Error: 34.7 → 11.0
Time: 7.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 -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}{2 \cdot a}\\ \mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.9721274759377412 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{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 -5.87486430558009272 \cdot 10^{54}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\
\;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}{2 \cdot a}\\

\mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r63061 = b;
        double r63062 = -r63061;
        double r63063 = r63061 * r63061;
        double r63064 = 4.0;
        double r63065 = a;
        double r63066 = r63064 * r63065;
        double r63067 = c;
        double r63068 = r63066 * r63067;
        double r63069 = r63063 - r63068;
        double r63070 = sqrt(r63069);
        double r63071 = r63062 + r63070;
        double r63072 = 2.0;
        double r63073 = r63072 * r63065;
        double r63074 = r63071 / r63073;
        return r63074;
}

double f(double a, double b, double c) {
        double r63075 = b;
        double r63076 = -5.874864305580093e+54;
        bool r63077 = r63075 <= r63076;
        double r63078 = 1.0;
        double r63079 = c;
        double r63080 = r63079 / r63075;
        double r63081 = a;
        double r63082 = r63075 / r63081;
        double r63083 = r63080 - r63082;
        double r63084 = r63078 * r63083;
        double r63085 = -9.847501781463365e+24;
        bool r63086 = r63075 <= r63085;
        double r63087 = 0.0;
        double r63088 = 4.0;
        double r63089 = r63081 * r63079;
        double r63090 = r63088 * r63089;
        double r63091 = r63087 + r63090;
        double r63092 = r63075 * r63075;
        double r63093 = r63088 * r63081;
        double r63094 = r63093 * r63079;
        double r63095 = r63092 - r63094;
        double r63096 = -r63095;
        double r63097 = fma(r63075, r63075, r63096);
        double r63098 = sqrt(r63095);
        double r63099 = r63098 - r63075;
        double r63100 = r63097 / r63099;
        double r63101 = r63091 / r63100;
        double r63102 = 2.0;
        double r63103 = r63102 * r63081;
        double r63104 = r63101 / r63103;
        double r63105 = -3.097985126053574e-61;
        bool r63106 = r63075 <= r63105;
        double r63107 = 6.972127475937741e+134;
        bool r63108 = r63075 <= r63107;
        double r63109 = 1.0;
        double r63110 = -r63075;
        double r63111 = r63110 - r63098;
        double r63112 = r63109 / r63111;
        double r63113 = r63102 / r63088;
        double r63114 = r63113 * r63109;
        double r63115 = r63114 / r63079;
        double r63116 = r63112 / r63115;
        double r63117 = r63109 * r63116;
        double r63118 = -1.0;
        double r63119 = r63118 * r63080;
        double r63120 = r63108 ? r63117 : r63119;
        double r63121 = r63106 ? r63084 : r63120;
        double r63122 = r63086 ? r63104 : r63121;
        double r63123 = r63077 ? r63084 : r63122;
        return r63123;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -5.874864305580093e+54 or -9.847501781463365e+24 < b < -3.097985126053574e-61

    1. Initial program 32.6

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

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

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

    if -5.874864305580093e+54 < b < -9.847501781463365e+24

    1. Initial program 5.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-+50.9

      \[\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. Simplified50.9

      \[\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 flip--50.9

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\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}\]
    7. Simplified49.3

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\color{blue}{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{2 \cdot a}\]
    8. Simplified49.3

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

    if -3.097985126053574e-61 < b < 6.972127475937741e+134

    1. Initial program 26.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 flip-+29.7

      \[\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. Simplified17.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 clear-num17.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied div-inv17.0

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

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

    if 6.972127475937741e+134 < 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. Taylor expanded around inf 2.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.87486430558009272 \cdot 10^{54}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -9.8475017814633646 \cdot 10^{24}:\\ \;\;\;\;\frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}}{2 \cdot a}\\ \mathbf{elif}\;b \le -3.09798512605357415 \cdot 10^{-61}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 6.9721274759377412 \cdot 10^{134}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{\frac{\frac{2}{4} \cdot 1}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020034 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))