Average Error: 24.5 → 5.7
Time: 21.8s
Precision: 64
\[\frac{{\left(s1 \cdot n2 - s2 \cdot n1\right)}^{2}}{n1 \cdot n2}\]
\[\begin{array}{l} \mathbf{if}\;s1 \le -1.2139282585255888 \cdot 10^{+154}:\\ \;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\ \mathbf{elif}\;s1 \le -1.8969759835305036 \cdot 10^{-70}:\\ \;\;\;\;\frac{\left(s1 \cdot s1\right) \cdot n2}{n1} + \left(-2 \cdot \left(s2 \cdot s1\right) + \frac{\left(s2 \cdot n1\right) \cdot s2}{n2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\ \end{array}\]
\frac{{\left(s1 \cdot n2 - s2 \cdot n1\right)}^{2}}{n1 \cdot n2}
\begin{array}{l}
\mathbf{if}\;s1 \le -1.2139282585255888 \cdot 10^{+154}:\\
\;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\

\mathbf{elif}\;s1 \le -1.8969759835305036 \cdot 10^{-70}:\\
\;\;\;\;\frac{\left(s1 \cdot s1\right) \cdot n2}{n1} + \left(-2 \cdot \left(s2 \cdot s1\right) + \frac{\left(s2 \cdot n1\right) \cdot s2}{n2}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\

\end{array}
double f(double s1, double n2, double s2, double n1) {
        double r17947283 = s1;
        double r17947284 = n2;
        double r17947285 = r17947283 * r17947284;
        double r17947286 = s2;
        double r17947287 = n1;
        double r17947288 = r17947286 * r17947287;
        double r17947289 = r17947285 - r17947288;
        double r17947290 = 2.0;
        double r17947291 = pow(r17947289, r17947290);
        double r17947292 = r17947287 * r17947284;
        double r17947293 = r17947291 / r17947292;
        return r17947293;
}

double f(double s1, double n2, double s2, double n1) {
        double r17947294 = s1;
        double r17947295 = -1.2139282585255888e+154;
        bool r17947296 = r17947294 <= r17947295;
        double r17947297 = n2;
        double r17947298 = r17947297 * r17947294;
        double r17947299 = s2;
        double r17947300 = n1;
        double r17947301 = r17947299 * r17947300;
        double r17947302 = r17947298 - r17947301;
        double r17947303 = r17947302 / r17947297;
        double r17947304 = r17947298 / r17947300;
        double r17947305 = r17947304 - r17947299;
        double r17947306 = r17947303 * r17947305;
        double r17947307 = -1.8969759835305036e-70;
        bool r17947308 = r17947294 <= r17947307;
        double r17947309 = r17947294 * r17947294;
        double r17947310 = r17947309 * r17947297;
        double r17947311 = r17947310 / r17947300;
        double r17947312 = -2.0;
        double r17947313 = r17947299 * r17947294;
        double r17947314 = r17947312 * r17947313;
        double r17947315 = r17947301 * r17947299;
        double r17947316 = r17947315 / r17947297;
        double r17947317 = r17947314 + r17947316;
        double r17947318 = r17947311 + r17947317;
        double r17947319 = r17947308 ? r17947318 : r17947306;
        double r17947320 = r17947296 ? r17947306 : r17947319;
        return r17947320;
}

Error

Bits error versus s1

Bits error versus n2

Bits error versus s2

Bits error versus n1

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if s1 < -1.2139282585255888e+154 or -1.8969759835305036e-70 < s1

    1. Initial program 23.8

      \[\frac{{\left(s1 \cdot n2 - s2 \cdot n1\right)}^{2}}{n1 \cdot n2}\]
    2. Simplified23.8

      \[\leadsto \color{blue}{\frac{\left(n2 \cdot s1 - s2 \cdot n1\right) \cdot \left(n2 \cdot s1 - s2 \cdot n1\right)}{n2 \cdot n1}}\]
    3. Using strategy rm
    4. Applied times-frac5.1

      \[\leadsto \color{blue}{\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \frac{n2 \cdot s1 - s2 \cdot n1}{n1}}\]
    5. Taylor expanded around inf 5.0

      \[\leadsto \frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \color{blue}{\left(\frac{s1 \cdot n2}{n1} - s2\right)}\]

    if -1.2139282585255888e+154 < s1 < -1.8969759835305036e-70

    1. Initial program 27.4

      \[\frac{{\left(s1 \cdot n2 - s2 \cdot n1\right)}^{2}}{n1 \cdot n2}\]
    2. Simplified27.4

      \[\leadsto \color{blue}{\frac{\left(n2 \cdot s1 - s2 \cdot n1\right) \cdot \left(n2 \cdot s1 - s2 \cdot n1\right)}{n2 \cdot n1}}\]
    3. Taylor expanded around -inf 12.5

      \[\leadsto \color{blue}{\left(\frac{{s2}^{2} \cdot n1}{n2} + \frac{{s1}^{2} \cdot n2}{n1}\right) - 2 \cdot \left(s1 \cdot s2\right)}\]
    4. Simplified8.9

      \[\leadsto \color{blue}{\frac{\left(s1 \cdot s1\right) \cdot n2}{n1} + \left(\frac{s2 \cdot \left(s2 \cdot n1\right)}{n2} + -2 \cdot \left(s2 \cdot s1\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;s1 \le -1.2139282585255888 \cdot 10^{+154}:\\ \;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\ \mathbf{elif}\;s1 \le -1.8969759835305036 \cdot 10^{-70}:\\ \;\;\;\;\frac{\left(s1 \cdot s1\right) \cdot n2}{n1} + \left(-2 \cdot \left(s2 \cdot s1\right) + \frac{\left(s2 \cdot n1\right) \cdot s2}{n2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{n2 \cdot s1 - s2 \cdot n1}{n2} \cdot \left(\frac{n2 \cdot s1}{n1} - s2\right)\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (s1 n2 s2 n1)
  :name "pow(s1*n2-s2*n1,2) /(n1*n2)"
  (/ (pow (- (* s1 n2) (* s2 n1)) 2) (* n1 n2)))