Given's Rotation SVD example, simplified

Percentage Accurate: 90.8% → 99.9%
Time: 13.6s
Alternatives: 13
Speedup: 1.7×

Specification

?
\[\begin{array}{l} \\ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
	return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
	return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x):
	return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x)
	return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))))
end
function tmp = code(x)
	tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 90.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
	return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
	return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x):
	return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x)
	return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))))
end
function tmp = code(x)
	tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}

Alternative 1: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_2 := 0.5 + t\_1\\ t_3 := \sqrt{t\_2}\\ \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\frac{\frac{0.25 + \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}}{-0.5 - t\_1}}{-1 - t\_3}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0024:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - t\_2}{1 + t\_3}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (pow x 2.0))))
        (t_1 (/ 0.5 (hypot 1.0 x)))
        (t_2 (+ 0.5 t_1))
        (t_3 (sqrt t_2)))
   (if (<= x -0.0017)
     (/ (/ (+ 0.25 (/ -0.25 (fma x x 1.0))) (- -0.5 t_1)) (- -1.0 t_3))
     (if (<= x -7e-60)
       t_0
       (if (<= x 7e-60)
         0.0
         (if (<= x 0.0024) t_0 (/ (- 1.0 t_2) (+ 1.0 t_3))))))))
double code(double x) {
	double t_0 = (-0.0859375 * pow(x, 4.0)) + (0.125 * pow(x, 2.0));
	double t_1 = 0.5 / hypot(1.0, x);
	double t_2 = 0.5 + t_1;
	double t_3 = sqrt(t_2);
	double tmp;
	if (x <= -0.0017) {
		tmp = ((0.25 + (-0.25 / fma(x, x, 1.0))) / (-0.5 - t_1)) / (-1.0 - t_3);
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0024) {
		tmp = t_0;
	} else {
		tmp = (1.0 - t_2) / (1.0 + t_3);
	}
	return tmp;
}
function code(x)
	t_0 = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * (x ^ 2.0)))
	t_1 = Float64(0.5 / hypot(1.0, x))
	t_2 = Float64(0.5 + t_1)
	t_3 = sqrt(t_2)
	tmp = 0.0
	if (x <= -0.0017)
		tmp = Float64(Float64(Float64(0.25 + Float64(-0.25 / fma(x, x, 1.0))) / Float64(-0.5 - t_1)) / Float64(-1.0 - t_3));
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0024)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 - t_2) / Float64(1.0 + t_3));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 + t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[t$95$2], $MachinePrecision]}, If[LessEqual[x, -0.0017], N[(N[(N[(0.25 + N[(-0.25 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-0.5 - t$95$1), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - t$95$3), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7e-60], t$95$0, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.0024], t$95$0, N[(N[(1.0 - t$95$2), $MachinePrecision] / N[(1.0 + t$95$3), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\
t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_2 := 0.5 + t\_1\\
t_3 := \sqrt{t\_2}\\
\mathbf{if}\;x \leq -0.0017:\\
\;\;\;\;\frac{\frac{0.25 + \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}}{-0.5 - t\_1}}{-1 - t\_3}\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.0024:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_2}{1 + t\_3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -0.00169999999999999991

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv98.2%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval98.2%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+99.9%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval99.9%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Step-by-step derivation
      1. flip--99.9%

        \[\leadsto \color{blue}{\frac{0.5 \cdot 0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. frac-2neg99.9%

        \[\leadsto \frac{0.5 \cdot 0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \color{blue}{\frac{-1}{-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
      3. metadata-eval99.9%

        \[\leadsto \frac{0.5 \cdot 0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \frac{\color{blue}{-1}}{-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      4. frac-times99.9%

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot 0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}} \]
      5. metadata-eval99.9%

        \[\leadsto \frac{\left(\color{blue}{0.25} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      6. frac-times99.8%

        \[\leadsto \frac{\left(0.25 - \color{blue}{\frac{0.5 \cdot 0.5}{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      7. metadata-eval99.8%

        \[\leadsto \frac{\left(0.25 - \frac{\color{blue}{0.25}}{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      8. hypot-udef99.8%

        \[\leadsto \frac{\left(0.25 - \frac{0.25}{\color{blue}{\sqrt{1 \cdot 1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right)}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      9. hypot-udef99.8%

        \[\leadsto \frac{\left(0.25 - \frac{0.25}{\sqrt{1 \cdot 1 + x \cdot x} \cdot \color{blue}{\sqrt{1 \cdot 1 + x \cdot x}}}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      10. rem-square-sqrt99.9%

        \[\leadsto \frac{\left(0.25 - \frac{0.25}{\color{blue}{1 \cdot 1 + x \cdot x}}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      11. metadata-eval99.9%

        \[\leadsto \frac{\left(0.25 - \frac{0.25}{\color{blue}{1} + x \cdot x}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
      12. unpow299.9%

        \[\leadsto \frac{\left(0.25 - \frac{0.25}{1 + \color{blue}{{x}^{2}}}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)} \]
    8. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{\left(0.25 - \frac{0.25}{1 + {x}^{2}}\right) \cdot -1}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(-1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}} \]
    9. Step-by-step derivation
      1. times-frac99.9%

        \[\leadsto \color{blue}{\frac{0.25 - \frac{0.25}{1 + {x}^{2}}}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \frac{-1}{-1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
      2. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{\frac{0.25 - \frac{0.25}{1 + {x}^{2}}}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot -1}{-1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
    10. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\frac{0.25 + \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}}{-0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{-1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]

    if -0.00169999999999999991 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 0.00239999999999999979

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]

    if 0.00239999999999999979 < x

    1. Initial program 98.2%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.2%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.2%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-neg98.2%

        \[\leadsto \color{blue}{1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      2. flip-+98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
      3. metadata-eval98.3%

        \[\leadsto \frac{\color{blue}{1} - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      4. pow198.3%

        \[\leadsto \frac{1 - \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1}} \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      5. pow198.3%

        \[\leadsto \frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1} \cdot \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      6. pow-prod-up98.3%

        \[\leadsto \frac{1 - \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{\left(1 + 1\right)}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      7. metadata-eval98.3%

        \[\leadsto \frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{\color{blue}{2}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
    6. Applied egg-rr98.3%

      \[\leadsto \color{blue}{\frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{2}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
    7. Step-by-step derivation
      1. unpow298.3%

        \[\leadsto \frac{1 - \color{blue}{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      2. sqr-neg98.3%

        \[\leadsto \frac{1 - \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      3. rem-square-sqrt99.8%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      4. sub-neg99.8%

        \[\leadsto \frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{\color{blue}{1 + \left(-\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}} \]
      5. remove-double-neg99.8%

        \[\leadsto \frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    8. Simplified99.8%

      \[\leadsto \color{blue}{\frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\frac{\frac{0.25 + \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}}{-0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{-1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0024:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_2 := 0.5 + t\_1\\ t_3 := 1 + \sqrt{t\_2}\\ \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\left(0.5 - t\_1\right) \cdot \frac{1}{t\_3}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0024:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - t\_2}{t\_3}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (pow x 2.0))))
        (t_1 (/ 0.5 (hypot 1.0 x)))
        (t_2 (+ 0.5 t_1))
        (t_3 (+ 1.0 (sqrt t_2))))
   (if (<= x -0.0017)
     (* (- 0.5 t_1) (/ 1.0 t_3))
     (if (<= x -7e-60)
       t_0
       (if (<= x 7e-60) 0.0 (if (<= x 0.0024) t_0 (/ (- 1.0 t_2) t_3)))))))
double code(double x) {
	double t_0 = (-0.0859375 * pow(x, 4.0)) + (0.125 * pow(x, 2.0));
	double t_1 = 0.5 / hypot(1.0, x);
	double t_2 = 0.5 + t_1;
	double t_3 = 1.0 + sqrt(t_2);
	double tmp;
	if (x <= -0.0017) {
		tmp = (0.5 - t_1) * (1.0 / t_3);
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0024) {
		tmp = t_0;
	} else {
		tmp = (1.0 - t_2) / t_3;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * Math.pow(x, 2.0));
	double t_1 = 0.5 / Math.hypot(1.0, x);
	double t_2 = 0.5 + t_1;
	double t_3 = 1.0 + Math.sqrt(t_2);
	double tmp;
	if (x <= -0.0017) {
		tmp = (0.5 - t_1) * (1.0 / t_3);
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0024) {
		tmp = t_0;
	} else {
		tmp = (1.0 - t_2) / t_3;
	}
	return tmp;
}
def code(x):
	t_0 = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * math.pow(x, 2.0))
	t_1 = 0.5 / math.hypot(1.0, x)
	t_2 = 0.5 + t_1
	t_3 = 1.0 + math.sqrt(t_2)
	tmp = 0
	if x <= -0.0017:
		tmp = (0.5 - t_1) * (1.0 / t_3)
	elif x <= -7e-60:
		tmp = t_0
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 0.0024:
		tmp = t_0
	else:
		tmp = (1.0 - t_2) / t_3
	return tmp
function code(x)
	t_0 = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * (x ^ 2.0)))
	t_1 = Float64(0.5 / hypot(1.0, x))
	t_2 = Float64(0.5 + t_1)
	t_3 = Float64(1.0 + sqrt(t_2))
	tmp = 0.0
	if (x <= -0.0017)
		tmp = Float64(Float64(0.5 - t_1) * Float64(1.0 / t_3));
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0024)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 - t_2) / t_3);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x ^ 2.0));
	t_1 = 0.5 / hypot(1.0, x);
	t_2 = 0.5 + t_1;
	t_3 = 1.0 + sqrt(t_2);
	tmp = 0.0;
	if (x <= -0.0017)
		tmp = (0.5 - t_1) * (1.0 / t_3);
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0024)
		tmp = t_0;
	else
		tmp = (1.0 - t_2) / t_3;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 + t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 + N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0017], N[(N[(0.5 - t$95$1), $MachinePrecision] * N[(1.0 / t$95$3), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7e-60], t$95$0, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.0024], t$95$0, N[(N[(1.0 - t$95$2), $MachinePrecision] / t$95$3), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\
t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_2 := 0.5 + t\_1\\
t_3 := 1 + \sqrt{t\_2}\\
\mathbf{if}\;x \leq -0.0017:\\
\;\;\;\;\left(0.5 - t\_1\right) \cdot \frac{1}{t\_3}\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.0024:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_2}{t\_3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -0.00169999999999999991

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv98.2%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval98.2%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+99.9%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval99.9%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]

    if -0.00169999999999999991 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 0.00239999999999999979

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]

    if 0.00239999999999999979 < x

    1. Initial program 98.2%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.2%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.2%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-neg98.2%

        \[\leadsto \color{blue}{1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      2. flip-+98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
      3. metadata-eval98.3%

        \[\leadsto \frac{\color{blue}{1} - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      4. pow198.3%

        \[\leadsto \frac{1 - \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1}} \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      5. pow198.3%

        \[\leadsto \frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1} \cdot \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{1}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      6. pow-prod-up98.3%

        \[\leadsto \frac{1 - \color{blue}{{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{\left(1 + 1\right)}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      7. metadata-eval98.3%

        \[\leadsto \frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{\color{blue}{2}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
    6. Applied egg-rr98.3%

      \[\leadsto \color{blue}{\frac{1 - {\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{2}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
    7. Step-by-step derivation
      1. unpow298.3%

        \[\leadsto \frac{1 - \color{blue}{\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      2. sqr-neg98.3%

        \[\leadsto \frac{1 - \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      3. rem-square-sqrt99.8%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)} \]
      4. sub-neg99.8%

        \[\leadsto \frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{\color{blue}{1 + \left(-\left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}} \]
      5. remove-double-neg99.8%

        \[\leadsto \frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    8. Simplified99.8%

      \[\leadsto \color{blue}{\frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0024:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_2 := \frac{0.5 - t\_1}{1 + \sqrt{0.5 + t\_1}}\\ \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0018:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (pow x 2.0))))
        (t_1 (/ 0.5 (hypot 1.0 x)))
        (t_2 (/ (- 0.5 t_1) (+ 1.0 (sqrt (+ 0.5 t_1))))))
   (if (<= x -0.0017)
     t_2
     (if (<= x -7e-60) t_0 (if (<= x 7e-60) 0.0 (if (<= x 0.0018) t_0 t_2))))))
double code(double x) {
	double t_0 = (-0.0859375 * pow(x, 4.0)) + (0.125 * pow(x, 2.0));
	double t_1 = 0.5 / hypot(1.0, x);
	double t_2 = (0.5 - t_1) / (1.0 + sqrt((0.5 + t_1)));
	double tmp;
	if (x <= -0.0017) {
		tmp = t_2;
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0018) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * Math.pow(x, 2.0));
	double t_1 = 0.5 / Math.hypot(1.0, x);
	double t_2 = (0.5 - t_1) / (1.0 + Math.sqrt((0.5 + t_1)));
	double tmp;
	if (x <= -0.0017) {
		tmp = t_2;
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0018) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x):
	t_0 = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * math.pow(x, 2.0))
	t_1 = 0.5 / math.hypot(1.0, x)
	t_2 = (0.5 - t_1) / (1.0 + math.sqrt((0.5 + t_1)))
	tmp = 0
	if x <= -0.0017:
		tmp = t_2
	elif x <= -7e-60:
		tmp = t_0
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 0.0018:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(x)
	t_0 = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * (x ^ 2.0)))
	t_1 = Float64(0.5 / hypot(1.0, x))
	t_2 = Float64(Float64(0.5 - t_1) / Float64(1.0 + sqrt(Float64(0.5 + t_1))))
	tmp = 0.0
	if (x <= -0.0017)
		tmp = t_2;
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0018)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x ^ 2.0));
	t_1 = 0.5 / hypot(1.0, x);
	t_2 = (0.5 - t_1) / (1.0 + sqrt((0.5 + t_1)));
	tmp = 0.0;
	if (x <= -0.0017)
		tmp = t_2;
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0018)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(0.5 - t$95$1), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0017], t$95$2, If[LessEqual[x, -7e-60], t$95$0, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.0018], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\
t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_2 := \frac{0.5 - t\_1}{1 + \sqrt{0.5 + t\_1}}\\
\mathbf{if}\;x \leq -0.0017:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.0018:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.00169999999999999991 or 0.0018 < x

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. metadata-eval98.3%

        \[\leadsto \frac{\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      3. add-sqr-sqrt99.8%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. associate--r+99.8%

        \[\leadsto \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. metadata-eval99.8%

        \[\leadsto \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]

    if -0.00169999999999999991 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 0.0018

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0018:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_2 := 0.5 - t\_1\\ t_3 := 1 + \sqrt{0.5 + t\_1}\\ \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;t\_2 \cdot \frac{1}{t\_3}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0018:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_2}{t\_3}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (pow x 2.0))))
        (t_1 (/ 0.5 (hypot 1.0 x)))
        (t_2 (- 0.5 t_1))
        (t_3 (+ 1.0 (sqrt (+ 0.5 t_1)))))
   (if (<= x -0.0017)
     (* t_2 (/ 1.0 t_3))
     (if (<= x -7e-60)
       t_0
       (if (<= x 7e-60) 0.0 (if (<= x 0.0018) t_0 (/ t_2 t_3)))))))
double code(double x) {
	double t_0 = (-0.0859375 * pow(x, 4.0)) + (0.125 * pow(x, 2.0));
	double t_1 = 0.5 / hypot(1.0, x);
	double t_2 = 0.5 - t_1;
	double t_3 = 1.0 + sqrt((0.5 + t_1));
	double tmp;
	if (x <= -0.0017) {
		tmp = t_2 * (1.0 / t_3);
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0018) {
		tmp = t_0;
	} else {
		tmp = t_2 / t_3;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * Math.pow(x, 2.0));
	double t_1 = 0.5 / Math.hypot(1.0, x);
	double t_2 = 0.5 - t_1;
	double t_3 = 1.0 + Math.sqrt((0.5 + t_1));
	double tmp;
	if (x <= -0.0017) {
		tmp = t_2 * (1.0 / t_3);
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.0018) {
		tmp = t_0;
	} else {
		tmp = t_2 / t_3;
	}
	return tmp;
}
def code(x):
	t_0 = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * math.pow(x, 2.0))
	t_1 = 0.5 / math.hypot(1.0, x)
	t_2 = 0.5 - t_1
	t_3 = 1.0 + math.sqrt((0.5 + t_1))
	tmp = 0
	if x <= -0.0017:
		tmp = t_2 * (1.0 / t_3)
	elif x <= -7e-60:
		tmp = t_0
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 0.0018:
		tmp = t_0
	else:
		tmp = t_2 / t_3
	return tmp
function code(x)
	t_0 = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * (x ^ 2.0)))
	t_1 = Float64(0.5 / hypot(1.0, x))
	t_2 = Float64(0.5 - t_1)
	t_3 = Float64(1.0 + sqrt(Float64(0.5 + t_1)))
	tmp = 0.0
	if (x <= -0.0017)
		tmp = Float64(t_2 * Float64(1.0 / t_3));
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0018)
		tmp = t_0;
	else
		tmp = Float64(t_2 / t_3);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x ^ 2.0));
	t_1 = 0.5 / hypot(1.0, x);
	t_2 = 0.5 - t_1;
	t_3 = 1.0 + sqrt((0.5 + t_1));
	tmp = 0.0;
	if (x <= -0.0017)
		tmp = t_2 * (1.0 / t_3);
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.0018)
		tmp = t_0;
	else
		tmp = t_2 / t_3;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 + N[Sqrt[N[(0.5 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0017], N[(t$95$2 * N[(1.0 / t$95$3), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7e-60], t$95$0, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.0018], t$95$0, N[(t$95$2 / t$95$3), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\
t_1 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_2 := 0.5 - t\_1\\
t_3 := 1 + \sqrt{0.5 + t\_1}\\
\mathbf{if}\;x \leq -0.0017:\\
\;\;\;\;t\_2 \cdot \frac{1}{t\_3}\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.0018:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_2}{t\_3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -0.00169999999999999991

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv98.2%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval98.2%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt99.8%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+99.9%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval99.9%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]

    if -0.00169999999999999991 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 0.0018

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]

    if 0.0018 < x

    1. Initial program 98.2%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.2%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.2%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.2%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.3%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. metadata-eval98.3%

        \[\leadsto \frac{\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      3. add-sqr-sqrt99.8%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. associate--r+99.7%

        \[\leadsto \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0017:\\ \;\;\;\;\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.0018:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ t_1 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{if}\;x \leq -0.00295:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.002:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))
        (t_1 (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (pow x 2.0)))))
   (if (<= x -0.00295)
     t_0
     (if (<= x -7e-60) t_1 (if (<= x 7e-60) 0.0 (if (<= x 0.002) t_1 t_0))))))
double code(double x) {
	double t_0 = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
	double t_1 = (-0.0859375 * pow(x, 4.0)) + (0.125 * pow(x, 2.0));
	double tmp;
	if (x <= -0.00295) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.002) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = 1.0 - Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))));
	double t_1 = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * Math.pow(x, 2.0));
	double tmp;
	if (x <= -0.00295) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.002) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = 1.0 - math.sqrt((0.5 + (0.5 / math.hypot(1.0, x))))
	t_1 = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * math.pow(x, 2.0))
	tmp = 0
	if x <= -0.00295:
		tmp = t_0
	elif x <= -7e-60:
		tmp = t_1
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 0.002:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))
	t_1 = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * (x ^ 2.0)))
	tmp = 0.0
	if (x <= -0.00295)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.002)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
	t_1 = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x ^ 2.0));
	tmp = 0.0;
	if (x <= -0.00295)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.002)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.00295], t$95$0, If[LessEqual[x, -7e-60], t$95$1, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.002], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
t_1 := -0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\
\mathbf{if}\;x \leq -0.00295:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.002:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.00294999999999999993 or 2e-3 < x

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing

    if -0.00294999999999999993 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 2e-3

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.00295:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.002:\\ \;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ t_1 := 0.125 \cdot {x}^{2}\\ \mathbf{if}\;x \leq -0.00014:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.000125:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))
        (t_1 (* 0.125 (pow x 2.0))))
   (if (<= x -0.00014)
     t_0
     (if (<= x -7e-60)
       t_1
       (if (<= x 7e-60) 0.0 (if (<= x 0.000125) t_1 t_0))))))
double code(double x) {
	double t_0 = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
	double t_1 = 0.125 * pow(x, 2.0);
	double tmp;
	if (x <= -0.00014) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.000125) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = 1.0 - Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))));
	double t_1 = 0.125 * Math.pow(x, 2.0);
	double tmp;
	if (x <= -0.00014) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 0.000125) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = 1.0 - math.sqrt((0.5 + (0.5 / math.hypot(1.0, x))))
	t_1 = 0.125 * math.pow(x, 2.0)
	tmp = 0
	if x <= -0.00014:
		tmp = t_0
	elif x <= -7e-60:
		tmp = t_1
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 0.000125:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))
	t_1 = Float64(0.125 * (x ^ 2.0))
	tmp = 0.0
	if (x <= -0.00014)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.000125)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
	t_1 = 0.125 * (x ^ 2.0);
	tmp = 0.0;
	if (x <= -0.00014)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 0.000125)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.00014], t$95$0, If[LessEqual[x, -7e-60], t$95$1, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 0.000125], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
t_1 := 0.125 \cdot {x}^{2}\\
\mathbf{if}\;x \leq -0.00014:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 0.000125:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.3999999999999999e-4 or 1.25e-4 < x

    1. Initial program 98.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing

    if -1.3999999999999999e-4 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 1.25e-4

    1. Initial program 5.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/5.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval5.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 99.1%

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.00014:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 0.000125:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 98.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ t_1 := 0.125 \cdot {x}^{2}\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 0.5 (+ 1.0 (sqrt 0.5)))) (t_1 (* 0.125 (pow x 2.0))))
   (if (<= x -1.5)
     t_0
     (if (<= x -7e-60) t_1 (if (<= x 7e-60) 0.0 (if (<= x 1.5) t_1 t_0))))))
double code(double x) {
	double t_0 = 0.5 / (1.0 + sqrt(0.5));
	double t_1 = 0.125 * pow(x, 2.0);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 / (1.0d0 + sqrt(0.5d0))
    t_1 = 0.125d0 * (x ** 2.0d0)
    if (x <= (-1.5d0)) then
        tmp = t_0
    else if (x <= (-7d-60)) then
        tmp = t_1
    else if (x <= 7d-60) then
        tmp = 0.0d0
    else if (x <= 1.5d0) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = 0.5 / (1.0 + Math.sqrt(0.5));
	double t_1 = 0.125 * Math.pow(x, 2.0);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = 0.5 / (1.0 + math.sqrt(0.5))
	t_1 = 0.125 * math.pow(x, 2.0)
	tmp = 0
	if x <= -1.5:
		tmp = t_0
	elif x <= -7e-60:
		tmp = t_1
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 1.5:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(0.5 / Float64(1.0 + sqrt(0.5)))
	t_1 = Float64(0.125 * (x ^ 2.0))
	tmp = 0.0
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = 0.5 / (1.0 + sqrt(0.5));
	t_1 = 0.125 * (x ^ 2.0);
	tmp = 0.0;
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(0.5 / N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5], t$95$0, If[LessEqual[x, -7e-60], t$95$1, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 1.5], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\
t_1 := 0.125 \cdot {x}^{2}\\
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.5 or 1.5 < x

    1. Initial program 98.5%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.5%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.5%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.5%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv98.5%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval98.5%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around inf 98.2%

      \[\leadsto \color{blue}{\frac{0.5}{1 + \sqrt{0.5}}} \]

    if -1.5 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 1.5

    1. Initial program 15.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/15.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified15.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 90.9%

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification98.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 98.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.125 \cdot {x}^{2}\\ \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* 0.125 (pow x 2.0))))
   (if (<= x -1.25)
     (/ (- 0.5 (/ -0.5 x)) (+ 1.0 (sqrt (+ 0.5 (/ -0.5 x)))))
     (if (<= x -7e-60)
       t_0
       (if (<= x 7e-60) 0.0 (if (<= x 1.5) t_0 (/ 0.5 (+ 1.0 (sqrt 0.5)))))))))
double code(double x) {
	double t_0 = 0.125 * pow(x, 2.0);
	double tmp;
	if (x <= -1.25) {
		tmp = (0.5 - (-0.5 / x)) / (1.0 + sqrt((0.5 + (-0.5 / x))));
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_0;
	} else {
		tmp = 0.5 / (1.0 + sqrt(0.5));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 0.125d0 * (x ** 2.0d0)
    if (x <= (-1.25d0)) then
        tmp = (0.5d0 - ((-0.5d0) / x)) / (1.0d0 + sqrt((0.5d0 + ((-0.5d0) / x))))
    else if (x <= (-7d-60)) then
        tmp = t_0
    else if (x <= 7d-60) then
        tmp = 0.0d0
    else if (x <= 1.5d0) then
        tmp = t_0
    else
        tmp = 0.5d0 / (1.0d0 + sqrt(0.5d0))
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = 0.125 * Math.pow(x, 2.0);
	double tmp;
	if (x <= -1.25) {
		tmp = (0.5 - (-0.5 / x)) / (1.0 + Math.sqrt((0.5 + (-0.5 / x))));
	} else if (x <= -7e-60) {
		tmp = t_0;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_0;
	} else {
		tmp = 0.5 / (1.0 + Math.sqrt(0.5));
	}
	return tmp;
}
def code(x):
	t_0 = 0.125 * math.pow(x, 2.0)
	tmp = 0
	if x <= -1.25:
		tmp = (0.5 - (-0.5 / x)) / (1.0 + math.sqrt((0.5 + (-0.5 / x))))
	elif x <= -7e-60:
		tmp = t_0
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 1.5:
		tmp = t_0
	else:
		tmp = 0.5 / (1.0 + math.sqrt(0.5))
	return tmp
function code(x)
	t_0 = Float64(0.125 * (x ^ 2.0))
	tmp = 0.0
	if (x <= -1.25)
		tmp = Float64(Float64(0.5 - Float64(-0.5 / x)) / Float64(1.0 + sqrt(Float64(0.5 + Float64(-0.5 / x)))));
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_0;
	else
		tmp = Float64(0.5 / Float64(1.0 + sqrt(0.5)));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = 0.125 * (x ^ 2.0);
	tmp = 0.0;
	if (x <= -1.25)
		tmp = (0.5 - (-0.5 / x)) / (1.0 + sqrt((0.5 + (-0.5 / x))));
	elseif (x <= -7e-60)
		tmp = t_0;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_0;
	else
		tmp = 0.5 / (1.0 + sqrt(0.5));
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.25], N[(N[(0.5 - N[(-0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7e-60], t$95$0, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 1.5], t$95$0, N[(0.5 / N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.125 \cdot {x}^{2}\\
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;\frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -1.25

    1. Initial program 98.5%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.5%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.5%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around -inf 97.6%

      \[\leadsto 1 - \sqrt{\color{blue}{0.5 - 0.5 \cdot \frac{1}{x}}} \]
    6. Step-by-step derivation
      1. associate-*r/97.6%

        \[\leadsto 1 - \sqrt{0.5 - \color{blue}{\frac{0.5 \cdot 1}{x}}} \]
      2. metadata-eval97.6%

        \[\leadsto 1 - \sqrt{0.5 - \frac{\color{blue}{0.5}}{x}} \]
    7. Simplified97.6%

      \[\leadsto 1 - \sqrt{\color{blue}{0.5 - \frac{0.5}{x}}} \]
    8. Step-by-step derivation
      1. flip--97.6%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 - \frac{0.5}{x}} \cdot \sqrt{0.5 - \frac{0.5}{x}}}{1 + \sqrt{0.5 - \frac{0.5}{x}}}} \]
      2. metadata-eval97.6%

        \[\leadsto \frac{\color{blue}{1} - \sqrt{0.5 - \frac{0.5}{x}} \cdot \sqrt{0.5 - \frac{0.5}{x}}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      3. add-sqr-sqrt99.1%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 - \frac{0.5}{x}\right)}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      4. sub-neg99.1%

        \[\leadsto \frac{1 - \color{blue}{\left(0.5 + \left(-\frac{0.5}{x}\right)\right)}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      5. associate--r+99.1%

        \[\leadsto \frac{\color{blue}{\left(1 - 0.5\right) - \left(-\frac{0.5}{x}\right)}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      6. metadata-eval99.1%

        \[\leadsto \frac{\color{blue}{0.5} - \left(-\frac{0.5}{x}\right)}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      7. distribute-neg-frac99.1%

        \[\leadsto \frac{0.5 - \color{blue}{\frac{-0.5}{x}}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      8. metadata-eval99.1%

        \[\leadsto \frac{0.5 - \frac{\color{blue}{-0.5}}{x}}{1 + \sqrt{0.5 - \frac{0.5}{x}}} \]
      9. sub-neg99.1%

        \[\leadsto \frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{\color{blue}{0.5 + \left(-\frac{0.5}{x}\right)}}} \]
      10. distribute-neg-frac99.1%

        \[\leadsto \frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \color{blue}{\frac{-0.5}{x}}}} \]
      11. metadata-eval99.1%

        \[\leadsto \frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{\color{blue}{-0.5}}{x}}} \]
    9. Applied egg-rr99.1%

      \[\leadsto \color{blue}{\frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}} \]

    if -1.25 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 1.5

    1. Initial program 15.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/15.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified15.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 90.9%

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]

    if 1.5 < x

    1. Initial program 98.5%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.5%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.5%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--98.5%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv98.5%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval98.5%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around inf 98.6%

      \[\leadsto \color{blue}{\frac{0.5}{1 + \sqrt{0.5}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\frac{0.5 - \frac{-0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 97.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ t_1 := 0.125 \cdot {x}^{2}\\ \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (sqrt 0.5))) (t_1 (* 0.125 (pow x 2.0))))
   (if (<= x -1.5)
     t_0
     (if (<= x -7e-60) t_1 (if (<= x 7e-60) 0.0 (if (<= x 1.5) t_1 t_0))))))
double code(double x) {
	double t_0 = 1.0 - sqrt(0.5);
	double t_1 = 0.125 * pow(x, 2.0);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 - sqrt(0.5d0)
    t_1 = 0.125d0 * (x ** 2.0d0)
    if (x <= (-1.5d0)) then
        tmp = t_0
    else if (x <= (-7d-60)) then
        tmp = t_1
    else if (x <= 7d-60) then
        tmp = 0.0d0
    else if (x <= 1.5d0) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = 1.0 - Math.sqrt(0.5);
	double t_1 = 0.125 * Math.pow(x, 2.0);
	double tmp;
	if (x <= -1.5) {
		tmp = t_0;
	} else if (x <= -7e-60) {
		tmp = t_1;
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else if (x <= 1.5) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = 1.0 - math.sqrt(0.5)
	t_1 = 0.125 * math.pow(x, 2.0)
	tmp = 0
	if x <= -1.5:
		tmp = t_0
	elif x <= -7e-60:
		tmp = t_1
	elif x <= 7e-60:
		tmp = 0.0
	elif x <= 1.5:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(1.0 - sqrt(0.5))
	t_1 = Float64(0.125 * (x ^ 2.0))
	tmp = 0.0
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = 1.0 - sqrt(0.5);
	t_1 = 0.125 * (x ^ 2.0);
	tmp = 0.0;
	if (x <= -1.5)
		tmp = t_0;
	elseif (x <= -7e-60)
		tmp = t_1;
	elseif (x <= 7e-60)
		tmp = 0.0;
	elseif (x <= 1.5)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5], t$95$0, If[LessEqual[x, -7e-60], t$95$1, If[LessEqual[x, 7e-60], 0.0, If[LessEqual[x, 1.5], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \sqrt{0.5}\\
t_1 := 0.125 \cdot {x}^{2}\\
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.5 or 1.5 < x

    1. Initial program 98.5%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/98.5%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval98.5%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified98.5%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 96.7%

      \[\leadsto \color{blue}{1 - \sqrt{0.5}} \]

    if -1.5 < x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x < 1.5

    1. Initial program 15.3%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/15.3%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval15.3%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified15.3%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 90.9%

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.5:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 89.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-60} \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -7e-60) (not (<= x 7e-60))) (- 1.0 (sqrt 0.5)) 0.0))
double code(double x) {
	double tmp;
	if ((x <= -7e-60) || !(x <= 7e-60)) {
		tmp = 1.0 - sqrt(0.5);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-7d-60)) .or. (.not. (x <= 7d-60))) then
        tmp = 1.0d0 - sqrt(0.5d0)
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -7e-60) || !(x <= 7e-60)) {
		tmp = 1.0 - Math.sqrt(0.5);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -7e-60) or not (x <= 7e-60):
		tmp = 1.0 - math.sqrt(0.5)
	else:
		tmp = 0.0
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -7e-60) || !(x <= 7e-60))
		tmp = Float64(1.0 - sqrt(0.5));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -7e-60) || ~((x <= 7e-60)))
		tmp = 1.0 - sqrt(0.5);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -7e-60], N[Not[LessEqual[x, 7e-60]], $MachinePrecision]], N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-60} \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\
\;\;\;\;1 - \sqrt{0.5}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.99999999999999952e-60 or 6.99999999999999952e-60 < x

    1. Initial program 84.6%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in84.6%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval84.6%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/84.6%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval84.6%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified84.6%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 82.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5}} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-60} \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 52.9% accurate, 12.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 7e-60))) (* 0.5 (- 0.5 (/ -0.5 x))) 0.0))
double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 7e-60)) {
		tmp = 0.5 * (0.5 - (-0.5 / x));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.0d0)) .or. (.not. (x <= 7d-60))) then
        tmp = 0.5d0 * (0.5d0 - ((-0.5d0) / x))
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 7e-60)) {
		tmp = 0.5 * (0.5 - (-0.5 / x));
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -1.0) or not (x <= 7e-60):
		tmp = 0.5 * (0.5 - (-0.5 / x))
	else:
		tmp = 0.0
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 7e-60))
		tmp = Float64(0.5 * Float64(0.5 - Float64(-0.5 / x)));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 7e-60)))
		tmp = 0.5 * (0.5 - (-0.5 / x));
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 7e-60]], $MachinePrecision]], N[(0.5 * N[(0.5 - N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\
\;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 6.99999999999999952e-60 < x

    1. Initial program 90.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in90.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval90.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/90.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval90.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified90.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--90.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv90.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval90.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt91.5%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+91.4%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval91.4%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr91.4%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 21.3%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around -inf 21.2%

      \[\leadsto \left(0.5 - \color{blue}{\frac{-0.5}{x}}\right) \cdot \frac{1}{2} \]

    if -1 < x < 6.99999999999999952e-60

    1. Initial program 91.4%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in91.4%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval91.4%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/91.4%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval91.4%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified91.4%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--91.4%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv91.4%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval91.4%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt91.4%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+91.5%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval91.5%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr91.5%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 91.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 90.4%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 7 \cdot 10^{-60}\right):\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 53.1% accurate, 12.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -7e-60)
   (* 0.5 (- 0.5 (/ 0.5 x)))
   (if (<= x 7e-60) 0.0 (* 0.5 (- 0.5 (/ -0.5 x))))))
double code(double x) {
	double tmp;
	if (x <= -7e-60) {
		tmp = 0.5 * (0.5 - (0.5 / x));
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else {
		tmp = 0.5 * (0.5 - (-0.5 / x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-7d-60)) then
        tmp = 0.5d0 * (0.5d0 - (0.5d0 / x))
    else if (x <= 7d-60) then
        tmp = 0.0d0
    else
        tmp = 0.5d0 * (0.5d0 - ((-0.5d0) / x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -7e-60) {
		tmp = 0.5 * (0.5 - (0.5 / x));
	} else if (x <= 7e-60) {
		tmp = 0.0;
	} else {
		tmp = 0.5 * (0.5 - (-0.5 / x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -7e-60:
		tmp = 0.5 * (0.5 - (0.5 / x))
	elif x <= 7e-60:
		tmp = 0.0
	else:
		tmp = 0.5 * (0.5 - (-0.5 / x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -7e-60)
		tmp = Float64(0.5 * Float64(0.5 - Float64(0.5 / x)));
	elseif (x <= 7e-60)
		tmp = 0.0;
	else
		tmp = Float64(0.5 * Float64(0.5 - Float64(-0.5 / x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -7e-60)
		tmp = 0.5 * (0.5 - (0.5 / x));
	elseif (x <= 7e-60)
		tmp = 0.0;
	else
		tmp = 0.5 * (0.5 - (-0.5 / x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -7e-60], N[(0.5 * N[(0.5 - N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7e-60], 0.0, N[(0.5 * N[(0.5 - N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-60}:\\
\;\;\;\;0.5 \cdot \left(0.5 - \frac{0.5}{x}\right)\\

\mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.99999999999999952e-60

    1. Initial program 86.5%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in86.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval86.5%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/86.5%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval86.5%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified86.5%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--86.5%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv86.4%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval86.4%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt87.8%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+87.9%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval87.9%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr87.9%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 20.8%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around inf 20.6%

      \[\leadsto \left(0.5 - \color{blue}{\frac{0.5}{x}}\right) \cdot \frac{1}{2} \]

    if -6.99999999999999952e-60 < x < 6.99999999999999952e-60

    1. Initial program 100.0%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/100.0%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval100.0%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt100.0%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+100.0%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval100.0%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around 0 100.0%

      \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]

    if 6.99999999999999952e-60 < x

    1. Initial program 82.8%

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Step-by-step derivation
      1. distribute-lft-in82.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
      2. metadata-eval82.8%

        \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
      3. associate-*r/82.8%

        \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. metadata-eval82.8%

        \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
    3. Simplified82.8%

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. flip--82.8%

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      2. div-inv82.8%

        \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
      3. metadata-eval82.8%

        \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      4. add-sqr-sqrt84.2%

        \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      5. associate--r+84.1%

        \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      6. metadata-eval84.1%

        \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied egg-rr84.1%

      \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    7. Taylor expanded in x around 0 20.1%

      \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
    8. Taylor expanded in x around -inf 19.8%

      \[\leadsto \left(0.5 - \color{blue}{\frac{-0.5}{x}}\right) \cdot \frac{1}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification51.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-60}:\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-60}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.5 - \frac{-0.5}{x}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 43.1% accurate, 210.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x) :precision binary64 0.0)
double code(double x) {
	return 0.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.0d0
end function
public static double code(double x) {
	return 0.0;
}
def code(x):
	return 0.0
function code(x)
	return 0.0
end
function tmp = code(x)
	tmp = 0.0;
end
code[x_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 90.6%

    \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
  2. Step-by-step derivation
    1. distribute-lft-in90.6%

      \[\leadsto 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}} \]
    2. metadata-eval90.6%

      \[\leadsto 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}} \]
    3. associate-*r/90.6%

      \[\leadsto 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. metadata-eval90.6%

      \[\leadsto 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}} \]
  3. Simplified90.6%

    \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. flip--90.6%

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    2. div-inv90.6%

      \[\leadsto \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    3. metadata-eval90.6%

      \[\leadsto \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    4. add-sqr-sqrt91.4%

      \[\leadsto \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    5. associate--r+91.4%

      \[\leadsto \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. metadata-eval91.4%

      \[\leadsto \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
  6. Applied egg-rr91.4%

    \[\leadsto \color{blue}{\left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  7. Taylor expanded in x around 0 51.5%

    \[\leadsto \left(0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{\color{blue}{2}} \]
  8. Taylor expanded in x around 0 41.0%

    \[\leadsto \left(0.5 - \color{blue}{0.5}\right) \cdot \frac{1}{2} \]
  9. Final simplification41.0%

    \[\leadsto 0 \]
  10. Add Preprocessing

Reproduce

?
herbie shell --seed 2024031 
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  :precision binary64
  (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))