Average Error: 26.0 → 7.3
Time: 10.5s
Precision: 64
\[\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.704555534625649921457110465502737538473 \cdot 10^{88}:\\ \;\;\;\;2 \cdot a - b\\ \mathbf{elif}\;b \le 6.072150405709616098866574063613437477933 \cdot 10^{127}:\\ \;\;\;\;\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\\ \mathbf{else}:\\ \;\;\;\;b - 2 \cdot a\\ \end{array}\]
\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}
\begin{array}{l}
\mathbf{if}\;b \le -4.704555534625649921457110465502737538473 \cdot 10^{88}:\\
\;\;\;\;2 \cdot a - b\\

\mathbf{elif}\;b \le 6.072150405709616098866574063613437477933 \cdot 10^{127}:\\
\;\;\;\;\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\\

\mathbf{else}:\\
\;\;\;\;b - 2 \cdot a\\

\end{array}
double f(double b, double a) {
        double r52161 = b;
        double r52162 = 2.0;
        double r52163 = pow(r52161, r52162);
        double r52164 = 4.0;
        double r52165 = a;
        double r52166 = r52164 * r52165;
        double r52167 = r52166 * r52161;
        double r52168 = r52163 - r52167;
        double r52169 = sqrt(r52168);
        return r52169;
}

double f(double b, double a) {
        double r52170 = b;
        double r52171 = -4.70455553462565e+88;
        bool r52172 = r52170 <= r52171;
        double r52173 = 2.0;
        double r52174 = a;
        double r52175 = r52173 * r52174;
        double r52176 = r52175 - r52170;
        double r52177 = 6.072150405709616e+127;
        bool r52178 = r52170 <= r52177;
        double r52179 = pow(r52170, r52173);
        double r52180 = 4.0;
        double r52181 = r52180 * r52174;
        double r52182 = r52181 * r52170;
        double r52183 = r52179 - r52182;
        double r52184 = sqrt(r52183);
        double r52185 = r52170 - r52175;
        double r52186 = r52178 ? r52184 : r52185;
        double r52187 = r52172 ? r52176 : r52186;
        return r52187;
}

Error

Bits error versus b

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if b < -4.70455553462565e+88

    1. Initial program 48.1

      \[\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\]
    2. Taylor expanded around -inf 5.6

      \[\leadsto \color{blue}{2 \cdot a - b}\]

    if -4.70455553462565e+88 < b < 6.072150405709616e+127

    1. Initial program 8.7

      \[\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\]

    if 6.072150405709616e+127 < b

    1. Initial program 56.5

      \[\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\]
    2. Taylor expanded around inf 5.0

      \[\leadsto \color{blue}{b - 2 \cdot a}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.704555534625649921457110465502737538473 \cdot 10^{88}:\\ \;\;\;\;2 \cdot a - b\\ \mathbf{elif}\;b \le 6.072150405709616098866574063613437477933 \cdot 10^{127}:\\ \;\;\;\;\sqrt{{b}^{2} - \left(4 \cdot a\right) \cdot b}\\ \mathbf{else}:\\ \;\;\;\;b - 2 \cdot a\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (b a)
  :name "sqrt(b^2-4*a*b)"
  :precision binary64
  (sqrt (- (pow b 2) (* (* 4 a) b))))