Given's Rotation SVD example

Percentage Accurate: 79.2% → 99.8%
Time: 12.6s
Alternatives: 9
Speedup: 0.9×

Specification

?
\[10^{-150} < \left|x\right| \land \left|x\right| < 10^{+150}\]
\[\begin{array}{l} \\ \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
	return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
	return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x):
	return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x)
	return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x)))))))
end
function tmp = code(p, x)
	tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\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 9 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: 79.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
	return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
	return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x):
	return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x)
	return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x)))))))
end
function tmp = code(p, x)
	tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}

Alternative 1: 99.8% accurate, 0.7× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.5:\\ \;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right) \cdot \frac{1}{x}}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.5)
   (- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x))
   (sqrt (+ 0.5 (/ 0.5 (* (hypot x (* p_m 2.0)) (/ 1.0 x)))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5) {
		tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = sqrt((0.5 + (0.5 / (hypot(x, (p_m * 2.0)) * (1.0 / x)))));
	}
	return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5) {
		tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = Math.sqrt((0.5 + (0.5 / (Math.hypot(x, (p_m * 2.0)) * (1.0 / x)))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5:
		tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x)
	else:
		tmp = math.sqrt((0.5 + (0.5 / (math.hypot(x, (p_m * 2.0)) * (1.0 / x)))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.5)
		tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x));
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(hypot(x, Float64(p_m * 2.0)) * Float64(1.0 / x)))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5)
		tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x);
	else
		tmp = sqrt((0.5 + (0.5 / (hypot(x, (p_m * 2.0)) * (1.0 / x)))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.5:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right) \cdot \frac{1}{x}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.5

    1. Initial program 20.6%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative20.6%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in20.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}}} \]
    6. Step-by-step derivation
      1. +-commutative44.9%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. mul-1-neg44.9%

        \[\leadsto -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + \color{blue}{\left(-\frac{p}{x}\right)} \]
      3. unsub-neg44.9%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} - \frac{p}{x}} \]
    7. Simplified54.1%

      \[\leadsto \color{blue}{\frac{-0.125}{{x}^{3}} \cdot \frac{\mathsf{fma}\left(-16, {p}^{4}, 4 \cdot {p}^{4}\right)}{p} - \frac{p}{x}} \]
    8. Taylor expanded in p around 0 54.2%

      \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}}} - \frac{p}{x} \]
    9. Step-by-step derivation
      1. *-commutative54.2%

        \[\leadsto \color{blue}{\frac{{p}^{3}}{{x}^{3}} \cdot 1.5} - \frac{p}{x} \]
      2. cube-div60.3%

        \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot 1.5 - \frac{p}{x} \]
    10. Simplified60.3%

      \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3} \cdot 1.5} - \frac{p}{x} \]

    if -0.5 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x))))

    1. Initial program 100.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in100.0%

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

      \[\leadsto \sqrt{\color{blue}{\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} \cdot 0.5 + 0.5}} \]
    5. Step-by-step derivation
      1. clear-num100.0%

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}} \cdot 0.5 + 0.5} \]
    9. Step-by-step derivation
      1. *-un-lft-identity100.0%

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(1, \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}, 0.5\right)}} \]
    11. Step-by-step derivation
      1. fma-undefine100.0%

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

        \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}} + 0.5} \]
    12. Simplified100.0%

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

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

      \[\leadsto \sqrt{\frac{0.5}{\color{blue}{\mathsf{hypot}\left(x, p \cdot 2\right) \cdot \frac{1}{x}}} + 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.5:\\ \;\;\;\;{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right) \cdot \frac{1}{x}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.8% accurate, 0.9× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+75} \lor \neg \left(x \leq -1.56 \cdot 10^{+31}\right) \land \left(x \leq -1.05 \cdot 10^{+22} \lor \neg \left(x \leq -8.5 \cdot 10^{-68}\right) \land x \leq -7.8 \cdot 10^{-84}\right):\\ \;\;\;\;\frac{p\_m}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (or (<= x -1.5e+75)
         (and (not (<= x -1.56e+31))
              (or (<= x -1.05e+22)
                  (and (not (<= x -8.5e-68)) (<= x -7.8e-84)))))
   (/ p_m (- x))
   (sqrt (+ 0.5 (* 0.5 (/ x (hypot x (* p_m 2.0))))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84))))) {
		tmp = p_m / -x;
	} else {
		tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p_m * 2.0))))));
	}
	return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84))))) {
		tmp = p_m / -x;
	} else {
		tmp = Math.sqrt((0.5 + (0.5 * (x / Math.hypot(x, (p_m * 2.0))))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if (x <= -1.5e+75) or (not (x <= -1.56e+31) and ((x <= -1.05e+22) or (not (x <= -8.5e-68) and (x <= -7.8e-84)))):
		tmp = p_m / -x
	else:
		tmp = math.sqrt((0.5 + (0.5 * (x / math.hypot(x, (p_m * 2.0))))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84)))))
		tmp = Float64(p_m / Float64(-x));
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(x / hypot(x, Float64(p_m * 2.0))))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if ((x <= -1.5e+75) || (~((x <= -1.56e+31)) && ((x <= -1.05e+22) || (~((x <= -8.5e-68)) && (x <= -7.8e-84)))))
		tmp = p_m / -x;
	else
		tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p_m * 2.0))))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[Or[LessEqual[x, -1.5e+75], And[N[Not[LessEqual[x, -1.56e+31]], $MachinePrecision], Or[LessEqual[x, -1.05e+22], And[N[Not[LessEqual[x, -8.5e-68]], $MachinePrecision], LessEqual[x, -7.8e-84]]]]], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 * N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+75} \lor \neg \left(x \leq -1.56 \cdot 10^{+31}\right) \land \left(x \leq -1.05 \cdot 10^{+22} \lor \neg \left(x \leq -8.5 \cdot 10^{-68}\right) \land x \leq -7.8 \cdot 10^{-84}\right):\\
\;\;\;\;\frac{p\_m}{-x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.5e75 or -1.56000000000000004e31 < x < -1.0499999999999999e22 or -8.50000000000000026e-68 < x < -7.80000000000000045e-84

    1. Initial program 36.3%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative36.3%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg36.3%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative36.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg46.2%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac246.2%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified46.2%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if -1.5e75 < x < -1.56000000000000004e31 or -1.0499999999999999e22 < x < -8.50000000000000026e-68 or -7.80000000000000045e-84 < x

    1. Initial program 87.4%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative87.4%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in87.4%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr87.4%

      \[\leadsto \sqrt{\color{blue}{\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} \cdot 0.5 + 0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+75} \lor \neg \left(x \leq -1.56 \cdot 10^{+31}\right) \land \left(x \leq -1.05 \cdot 10^{+22} \lor \neg \left(x \leq -8.5 \cdot 10^{-68}\right) \land x \leq -7.8 \cdot 10^{-84}\right):\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.9% accurate, 0.9× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x, p\_m \cdot 2\right)\\ t_1 := \frac{p\_m}{-x}\\ t_2 := \sqrt{0.5 + 0.5 \cdot \frac{x}{t\_0}}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+75}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{+32}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+22}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-67}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-82}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\frac{t\_0}{x}}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (let* ((t_0 (hypot x (* p_m 2.0)))
        (t_1 (/ p_m (- x)))
        (t_2 (sqrt (+ 0.5 (* 0.5 (/ x t_0))))))
   (if (<= x -1e+75)
     t_1
     (if (<= x -1.75e+32)
       t_2
       (if (<= x -2.1e+22)
         t_1
         (if (<= x -1.05e-67)
           t_2
           (if (<= x -1.7e-82) t_1 (sqrt (+ 0.5 (/ 0.5 (/ t_0 x)))))))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double t_0 = hypot(x, (p_m * 2.0));
	double t_1 = p_m / -x;
	double t_2 = sqrt((0.5 + (0.5 * (x / t_0))));
	double tmp;
	if (x <= -1e+75) {
		tmp = t_1;
	} else if (x <= -1.75e+32) {
		tmp = t_2;
	} else if (x <= -2.1e+22) {
		tmp = t_1;
	} else if (x <= -1.05e-67) {
		tmp = t_2;
	} else if (x <= -1.7e-82) {
		tmp = t_1;
	} else {
		tmp = sqrt((0.5 + (0.5 / (t_0 / x))));
	}
	return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double t_0 = Math.hypot(x, (p_m * 2.0));
	double t_1 = p_m / -x;
	double t_2 = Math.sqrt((0.5 + (0.5 * (x / t_0))));
	double tmp;
	if (x <= -1e+75) {
		tmp = t_1;
	} else if (x <= -1.75e+32) {
		tmp = t_2;
	} else if (x <= -2.1e+22) {
		tmp = t_1;
	} else if (x <= -1.05e-67) {
		tmp = t_2;
	} else if (x <= -1.7e-82) {
		tmp = t_1;
	} else {
		tmp = Math.sqrt((0.5 + (0.5 / (t_0 / x))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	t_0 = math.hypot(x, (p_m * 2.0))
	t_1 = p_m / -x
	t_2 = math.sqrt((0.5 + (0.5 * (x / t_0))))
	tmp = 0
	if x <= -1e+75:
		tmp = t_1
	elif x <= -1.75e+32:
		tmp = t_2
	elif x <= -2.1e+22:
		tmp = t_1
	elif x <= -1.05e-67:
		tmp = t_2
	elif x <= -1.7e-82:
		tmp = t_1
	else:
		tmp = math.sqrt((0.5 + (0.5 / (t_0 / x))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	t_0 = hypot(x, Float64(p_m * 2.0))
	t_1 = Float64(p_m / Float64(-x))
	t_2 = sqrt(Float64(0.5 + Float64(0.5 * Float64(x / t_0))))
	tmp = 0.0
	if (x <= -1e+75)
		tmp = t_1;
	elseif (x <= -1.75e+32)
		tmp = t_2;
	elseif (x <= -2.1e+22)
		tmp = t_1;
	elseif (x <= -1.05e-67)
		tmp = t_2;
	elseif (x <= -1.7e-82)
		tmp = t_1;
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(t_0 / x))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	t_0 = hypot(x, (p_m * 2.0));
	t_1 = p_m / -x;
	t_2 = sqrt((0.5 + (0.5 * (x / t_0))));
	tmp = 0.0;
	if (x <= -1e+75)
		tmp = t_1;
	elseif (x <= -1.75e+32)
		tmp = t_2;
	elseif (x <= -2.1e+22)
		tmp = t_1;
	elseif (x <= -1.05e-67)
		tmp = t_2;
	elseif (x <= -1.7e-82)
		tmp = t_1;
	else
		tmp = sqrt((0.5 + (0.5 / (t_0 / x))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(p$95$m / (-x)), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(0.5 + N[(0.5 * N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1e+75], t$95$1, If[LessEqual[x, -1.75e+32], t$95$2, If[LessEqual[x, -2.1e+22], t$95$1, If[LessEqual[x, -1.05e-67], t$95$2, If[LessEqual[x, -1.7e-82], t$95$1, N[Sqrt[N[(0.5 + N[(0.5 / N[(t$95$0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]]
\begin{array}{l}
p_m = \left|p\right|

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

\mathbf{elif}\;x \leq -1.75 \cdot 10^{+32}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x \leq -2.1 \cdot 10^{+22}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -1.05 \cdot 10^{-67}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x \leq -1.7 \cdot 10^{-82}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\frac{t\_0}{x}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -9.99999999999999927e74 or -1.75e32 < x < -2.0999999999999998e22 or -1.0500000000000001e-67 < x < -1.69999999999999988e-82

    1. Initial program 36.3%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative36.3%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg36.3%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*36.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative36.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg46.2%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac246.2%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified46.2%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if -9.99999999999999927e74 < x < -1.75e32 or -2.0999999999999998e22 < x < -1.0500000000000001e-67

    1. Initial program 70.7%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative70.7%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in70.7%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr70.7%

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

    if -1.69999999999999988e-82 < x

    1. Initial program 92.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative92.9%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in92.9%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr92.9%

      \[\leadsto \sqrt{\color{blue}{\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} \cdot 0.5 + 0.5}} \]
    5. Step-by-step derivation
      1. clear-num92.9%

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}} \cdot 0.5 + 0.5} \]
    9. Step-by-step derivation
      1. *-un-lft-identity92.9%

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

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(1, \frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}} \cdot 0.5, 0.5\right)}} \]
      3. associate-*l/92.9%

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

        \[\leadsto \sqrt{\mathsf{fma}\left(1, \frac{\color{blue}{0.5}}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}, 0.5\right)} \]
    10. Applied egg-rr92.9%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(1, \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}, 0.5\right)}} \]
    11. Step-by-step derivation
      1. fma-undefine92.9%

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}} + 0.5}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification80.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+75}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+22}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-67}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-82}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 69.4% accurate, 1.7× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;p\_m \leq 1.2 \cdot 10^{-146}:\\ \;\;\;\;\frac{p\_m}{-x}\\ \mathbf{elif}\;p\_m \leq 1.1 \cdot 10^{-112}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\ \mathbf{elif}\;p\_m \leq 7.5 \cdot 10^{-47}:\\ \;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{0.25 \cdot \frac{x}{p\_m} + \frac{p\_m}{x} \cdot 2}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= p_m 1.2e-146)
   (/ p_m (- x))
   (if (<= p_m 1.1e-112)
     (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
     (if (<= p_m 7.5e-47)
       (- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x))
       (sqrt (+ 0.5 (/ 0.5 (+ (* 0.25 (/ x p_m)) (* (/ p_m x) 2.0)))))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (p_m <= 1.2e-146) {
		tmp = p_m / -x;
	} else if (p_m <= 1.1e-112) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 7.5e-47) {
		tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))));
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: tmp
    if (p_m <= 1.2d-146) then
        tmp = p_m / -x
    else if (p_m <= 1.1d-112) then
        tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
    else if (p_m <= 7.5d-47) then
        tmp = (((p_m / x) ** 3.0d0) * 1.5d0) - (p_m / x)
    else
        tmp = sqrt((0.5d0 + (0.5d0 / ((0.25d0 * (x / p_m)) + ((p_m / x) * 2.0d0)))))
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if (p_m <= 1.2e-146) {
		tmp = p_m / -x;
	} else if (p_m <= 1.1e-112) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 7.5e-47) {
		tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = Math.sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if p_m <= 1.2e-146:
		tmp = p_m / -x
	elif p_m <= 1.1e-112:
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)))
	elif p_m <= 7.5e-47:
		tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x)
	else:
		tmp = math.sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (p_m <= 1.2e-146)
		tmp = Float64(p_m / Float64(-x));
	elseif (p_m <= 1.1e-112)
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x))));
	elseif (p_m <= 7.5e-47)
		tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x));
	else
		tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(Float64(0.25 * Float64(x / p_m)) + Float64(Float64(p_m / x) * 2.0)))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (p_m <= 1.2e-146)
		tmp = p_m / -x;
	elseif (p_m <= 1.1e-112)
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	elseif (p_m <= 7.5e-47)
		tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x);
	else
		tmp = sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[p$95$m, 1.2e-146], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 1.1e-112], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 7.5e-47], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[(N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(p$95$m / x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{p\_m}{-x}\\

\mathbf{elif}\;p\_m \leq 1.1 \cdot 10^{-112}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\

\mathbf{elif}\;p\_m \leq 7.5 \cdot 10^{-47}:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{0.25 \cdot \frac{x}{p\_m} + \frac{p\_m}{x} \cdot 2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 1.2000000000000001e-146

    1. Initial program 76.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative76.9%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg76.9%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*76.9%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified76.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg17.7%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac217.7%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified17.7%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if 1.2000000000000001e-146 < p < 1.10000000000000011e-112

    1. Initial program 80.4%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative80.4%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*80.4%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified80.7%

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 74.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative74.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified74.7%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow274.7%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow274.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac74.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr74.7%

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

    if 1.10000000000000011e-112 < p < 7.49999999999999969e-47

    1. Initial program 49.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative49.0%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in49.0%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr49.0%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}}} \]
    6. Step-by-step derivation
      1. +-commutative54.0%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. mul-1-neg54.0%

        \[\leadsto -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + \color{blue}{\left(-\frac{p}{x}\right)} \]
      3. unsub-neg54.0%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} - \frac{p}{x}} \]
    7. Simplified54.1%

      \[\leadsto \color{blue}{\frac{-0.125}{{x}^{3}} \cdot \frac{\mathsf{fma}\left(-16, {p}^{4}, 4 \cdot {p}^{4}\right)}{p} - \frac{p}{x}} \]
    8. Taylor expanded in p around 0 54.3%

      \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}}} - \frac{p}{x} \]
    9. Step-by-step derivation
      1. *-commutative54.3%

        \[\leadsto \color{blue}{\frac{{p}^{3}}{{x}^{3}} \cdot 1.5} - \frac{p}{x} \]
      2. cube-div54.6%

        \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot 1.5 - \frac{p}{x} \]
    10. Simplified54.6%

      \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3} \cdot 1.5} - \frac{p}{x} \]

    if 7.49999999999999969e-47 < p

    1. Initial program 92.5%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative92.5%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in92.5%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr92.5%

      \[\leadsto \sqrt{\color{blue}{\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} \cdot 0.5 + 0.5}} \]
    5. Step-by-step derivation
      1. clear-num92.5%

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}} \cdot 0.5 + 0.5} \]
    9. Step-by-step derivation
      1. *-un-lft-identity92.5%

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

        \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(1, \frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}} \cdot 0.5, 0.5\right)}} \]
      3. associate-*l/92.5%

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

        \[\leadsto \sqrt{\mathsf{fma}\left(1, \frac{\color{blue}{0.5}}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}, 0.5\right)} \]
    10. Applied egg-rr92.5%

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(1, \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}, 0.5\right)}} \]
    11. Step-by-step derivation
      1. fma-undefine92.5%

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

        \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}} + 0.5} \]
    12. Simplified92.5%

      \[\leadsto \sqrt{\color{blue}{\frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}} + 0.5}} \]
    13. Taylor expanded in x around 0 87.3%

      \[\leadsto \sqrt{\frac{0.5}{\color{blue}{0.25 \cdot \frac{x}{p} + 2 \cdot \frac{p}{x}}} + 0.5} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification38.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.2 \cdot 10^{-146}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;p \leq 1.1 \cdot 10^{-112}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 7.5 \cdot 10^{-47}:\\ \;\;\;\;{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{0.5}{0.25 \cdot \frac{x}{p} + \frac{p}{x} \cdot 2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 68.1% accurate, 1.7× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;p\_m \leq 2.7 \cdot 10^{-149}:\\ \;\;\;\;\frac{p\_m}{-x}\\ \mathbf{elif}\;p\_m \leq 6.8 \cdot 10^{-113}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\ \mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\ \;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= p_m 2.7e-149)
   (/ p_m (- x))
   (if (<= p_m 6.8e-113)
     (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
     (if (<= p_m 1.12e-35)
       (- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x))
       (sqrt (+ 0.5 (* 0.25 (/ x p_m))))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (p_m <= 2.7e-149) {
		tmp = p_m / -x;
	} else if (p_m <= 6.8e-113) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 1.12e-35) {
		tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = sqrt((0.5 + (0.25 * (x / p_m))));
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: tmp
    if (p_m <= 2.7d-149) then
        tmp = p_m / -x
    else if (p_m <= 6.8d-113) then
        tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
    else if (p_m <= 1.12d-35) then
        tmp = (((p_m / x) ** 3.0d0) * 1.5d0) - (p_m / x)
    else
        tmp = sqrt((0.5d0 + (0.25d0 * (x / p_m))))
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if (p_m <= 2.7e-149) {
		tmp = p_m / -x;
	} else if (p_m <= 6.8e-113) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 1.12e-35) {
		tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
	} else {
		tmp = Math.sqrt((0.5 + (0.25 * (x / p_m))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if p_m <= 2.7e-149:
		tmp = p_m / -x
	elif p_m <= 6.8e-113:
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)))
	elif p_m <= 1.12e-35:
		tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x)
	else:
		tmp = math.sqrt((0.5 + (0.25 * (x / p_m))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (p_m <= 2.7e-149)
		tmp = Float64(p_m / Float64(-x));
	elseif (p_m <= 6.8e-113)
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x))));
	elseif (p_m <= 1.12e-35)
		tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x));
	else
		tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p_m))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (p_m <= 2.7e-149)
		tmp = p_m / -x;
	elseif (p_m <= 6.8e-113)
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	elseif (p_m <= 1.12e-35)
		tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x);
	else
		tmp = sqrt((0.5 + (0.25 * (x / p_m))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[p$95$m, 2.7e-149], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 6.8e-113], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.12e-35], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 2.7 \cdot 10^{-149}:\\
\;\;\;\;\frac{p\_m}{-x}\\

\mathbf{elif}\;p\_m \leq 6.8 \cdot 10^{-113}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\

\mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 2.70000000000000014e-149

    1. Initial program 76.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative76.9%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define76.9%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg76.9%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*76.9%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified76.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg17.7%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac217.7%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified17.7%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if 2.70000000000000014e-149 < p < 6.8000000000000005e-113

    1. Initial program 80.4%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative80.4%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*80.4%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified80.7%

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 74.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative74.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified74.7%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow274.7%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow274.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac74.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr74.7%

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

    if 6.8000000000000005e-113 < p < 1.12e-35

    1. Initial program 46.2%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative46.2%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. distribute-rgt-in46.2%

        \[\leadsto \sqrt{\color{blue}{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot 0.5 + 1 \cdot 0.5}} \]
    4. Applied egg-rr46.2%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}}} \]
    6. Step-by-step derivation
      1. +-commutative56.9%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. mul-1-neg56.9%

        \[\leadsto -0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} + \color{blue}{\left(-\frac{p}{x}\right)} \]
      3. unsub-neg56.9%

        \[\leadsto \color{blue}{-0.125 \cdot \frac{-16 \cdot {p}^{4} + {\left(-2 \cdot {p}^{2}\right)}^{2}}{p \cdot {x}^{3}} - \frac{p}{x}} \]
    7. Simplified57.0%

      \[\leadsto \color{blue}{\frac{-0.125}{{x}^{3}} \cdot \frac{\mathsf{fma}\left(-16, {p}^{4}, 4 \cdot {p}^{4}\right)}{p} - \frac{p}{x}} \]
    8. Taylor expanded in p around 0 57.2%

      \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}}} - \frac{p}{x} \]
    9. Step-by-step derivation
      1. *-commutative57.2%

        \[\leadsto \color{blue}{\frac{{p}^{3}}{{x}^{3}} \cdot 1.5} - \frac{p}{x} \]
      2. cube-div57.5%

        \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot 1.5 - \frac{p}{x} \]
    10. Simplified57.5%

      \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3} \cdot 1.5} - \frac{p}{x} \]

    if 1.12e-35 < p

    1. Initial program 93.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 86.7%

      \[\leadsto \sqrt{\color{blue}{0.5 + 0.25 \cdot \frac{x}{p}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification38.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 2.7 \cdot 10^{-149}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;p \leq 6.8 \cdot 10^{-113}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 1.12 \cdot 10^{-35}:\\ \;\;\;\;{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 68.2% accurate, 1.8× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} t_0 := \frac{p\_m}{-x}\\ \mathbf{if}\;p\_m \leq 4.2 \cdot 10^{-146}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;p\_m \leq 9.8 \cdot 10^{-113}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\ \mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (let* ((t_0 (/ p_m (- x))))
   (if (<= p_m 4.2e-146)
     t_0
     (if (<= p_m 9.8e-113)
       (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
       (if (<= p_m 1.12e-35) t_0 (sqrt (+ 0.5 (* 0.25 (/ x p_m)))))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double t_0 = p_m / -x;
	double tmp;
	if (p_m <= 4.2e-146) {
		tmp = t_0;
	} else if (p_m <= 9.8e-113) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 1.12e-35) {
		tmp = t_0;
	} else {
		tmp = sqrt((0.5 + (0.25 * (x / p_m))));
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = p_m / -x
    if (p_m <= 4.2d-146) then
        tmp = t_0
    else if (p_m <= 9.8d-113) then
        tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
    else if (p_m <= 1.12d-35) then
        tmp = t_0
    else
        tmp = sqrt((0.5d0 + (0.25d0 * (x / p_m))))
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double t_0 = p_m / -x;
	double tmp;
	if (p_m <= 4.2e-146) {
		tmp = t_0;
	} else if (p_m <= 9.8e-113) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 1.12e-35) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt((0.5 + (0.25 * (x / p_m))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	t_0 = p_m / -x
	tmp = 0
	if p_m <= 4.2e-146:
		tmp = t_0
	elif p_m <= 9.8e-113:
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)))
	elif p_m <= 1.12e-35:
		tmp = t_0
	else:
		tmp = math.sqrt((0.5 + (0.25 * (x / p_m))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	t_0 = Float64(p_m / Float64(-x))
	tmp = 0.0
	if (p_m <= 4.2e-146)
		tmp = t_0;
	elseif (p_m <= 9.8e-113)
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x))));
	elseif (p_m <= 1.12e-35)
		tmp = t_0;
	else
		tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p_m))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	t_0 = p_m / -x;
	tmp = 0.0;
	if (p_m <= 4.2e-146)
		tmp = t_0;
	elseif (p_m <= 9.8e-113)
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	elseif (p_m <= 1.12e-35)
		tmp = t_0;
	else
		tmp = sqrt((0.5 + (0.25 * (x / p_m))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[(p$95$m / (-x)), $MachinePrecision]}, If[LessEqual[p$95$m, 4.2e-146], t$95$0, If[LessEqual[p$95$m, 9.8e-113], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.12e-35], t$95$0, N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
t_0 := \frac{p\_m}{-x}\\
\mathbf{if}\;p\_m \leq 4.2 \cdot 10^{-146}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 9.8 \cdot 10^{-113}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\

\mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 4.1999999999999998e-146 or 9.8000000000000006e-113 < p < 1.12e-35

    1. Initial program 74.3%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative74.3%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg74.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*74.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg74.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define74.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg74.3%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*74.3%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative74.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg21.1%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac221.1%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified21.1%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if 4.1999999999999998e-146 < p < 9.8000000000000006e-113

    1. Initial program 80.4%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative80.4%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*80.4%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified80.7%

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 74.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative74.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified74.7%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow274.7%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow274.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac74.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr74.7%

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

    if 1.12e-35 < p

    1. Initial program 93.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 86.7%

      \[\leadsto \sqrt{\color{blue}{0.5 + 0.25 \cdot \frac{x}{p}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification38.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 4.2 \cdot 10^{-146}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;p \leq 9.8 \cdot 10^{-113}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 1.12 \cdot 10^{-35}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.9% accurate, 1.9× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} t_0 := \frac{p\_m}{-x}\\ \mathbf{if}\;p\_m \leq 6.8 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;p\_m \leq 1.35 \cdot 10^{-112}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\ \mathbf{elif}\;p\_m \leq 3.8 \cdot 10^{-47}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (let* ((t_0 (/ p_m (- x))))
   (if (<= p_m 6.8e-147)
     t_0
     (if (<= p_m 1.35e-112)
       (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
       (if (<= p_m 3.8e-47) t_0 (sqrt 0.5))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double t_0 = p_m / -x;
	double tmp;
	if (p_m <= 6.8e-147) {
		tmp = t_0;
	} else if (p_m <= 1.35e-112) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 3.8e-47) {
		tmp = t_0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = p_m / -x
    if (p_m <= 6.8d-147) then
        tmp = t_0
    else if (p_m <= 1.35d-112) then
        tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
    else if (p_m <= 3.8d-47) then
        tmp = t_0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double t_0 = p_m / -x;
	double tmp;
	if (p_m <= 6.8e-147) {
		tmp = t_0;
	} else if (p_m <= 1.35e-112) {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	} else if (p_m <= 3.8e-47) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	t_0 = p_m / -x
	tmp = 0
	if p_m <= 6.8e-147:
		tmp = t_0
	elif p_m <= 1.35e-112:
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)))
	elif p_m <= 3.8e-47:
		tmp = t_0
	else:
		tmp = math.sqrt(0.5)
	return tmp
p_m = abs(p)
function code(p_m, x)
	t_0 = Float64(p_m / Float64(-x))
	tmp = 0.0
	if (p_m <= 6.8e-147)
		tmp = t_0;
	elseif (p_m <= 1.35e-112)
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x))));
	elseif (p_m <= 3.8e-47)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	t_0 = p_m / -x;
	tmp = 0.0;
	if (p_m <= 6.8e-147)
		tmp = t_0;
	elseif (p_m <= 1.35e-112)
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	elseif (p_m <= 3.8e-47)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[(p$95$m / (-x)), $MachinePrecision]}, If[LessEqual[p$95$m, 6.8e-147], t$95$0, If[LessEqual[p$95$m, 1.35e-112], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 3.8e-47], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
t_0 := \frac{p\_m}{-x}\\
\mathbf{if}\;p\_m \leq 6.8 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 1.35 \cdot 10^{-112}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\

\mathbf{elif}\;p\_m \leq 3.8 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 6.79999999999999991e-147 or 1.35e-112 < p < 3.80000000000000015e-47

    1. Initial program 74.6%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative74.6%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*74.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative74.6%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified74.6%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg20.6%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac220.6%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified20.6%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if 6.79999999999999991e-147 < p < 1.35e-112

    1. Initial program 80.4%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative80.4%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define80.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*80.4%

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified80.7%

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 74.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative74.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified74.7%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow274.7%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow274.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac74.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr74.7%

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

    if 3.80000000000000015e-47 < p

    1. Initial program 92.5%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 84.6%

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification37.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 6.8 \cdot 10^{-147}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{elif}\;p \leq 1.35 \cdot 10^{-112}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 3.8 \cdot 10^{-47}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 51.0% accurate, 13.4× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;x \leq 3 \cdot 10^{-149}:\\ \;\;\;\;\frac{p\_m}{-x}\\ \mathbf{else}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= x 3e-149) (/ p_m (- x)) (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (x <= 3e-149) {
		tmp = p_m / -x;
	} else {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3d-149) then
        tmp = p_m / -x
    else
        tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if (x <= 3e-149) {
		tmp = p_m / -x;
	} else {
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if x <= 3e-149:
		tmp = p_m / -x
	else:
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (x <= 3e-149)
		tmp = Float64(p_m / Float64(-x));
	else
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (x <= 3e-149)
		tmp = p_m / -x;
	else
		tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[x, 3e-149], N[(p$95$m / (-x)), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3 \cdot 10^{-149}:\\
\;\;\;\;\frac{p\_m}{-x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.0000000000000002e-149

    1. Initial program 58.5%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative58.5%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*58.5%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative58.5%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
    3. Simplified58.5%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    6. Step-by-step derivation
      1. mul-1-neg33.0%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac233.0%

        \[\leadsto \color{blue}{\frac{p}{-x}} \]
    7. Simplified33.0%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]

    if 3.0000000000000002e-149 < x

    1. Initial program 100.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
      2. sqr-neg100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
      3. associate-*l*100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
      4. sqr-neg100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
      5. fma-define100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
      6. sqr-neg100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
      7. fma-define100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
      8. associate-*l*100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
      9. +-commutative100.0%

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

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 47.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative47.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified47.7%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow247.7%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow247.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac47.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr47.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3 \cdot 10^{-149}:\\ \;\;\;\;\frac{p}{-x}\\ \mathbf{else}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 27.0% accurate, 53.8× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \frac{p\_m}{-x} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x) :precision binary64 (/ p_m (- x)))
p_m = fabs(p);
double code(double p_m, double x) {
	return p_m / -x;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    code = p_m / -x
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	return p_m / -x;
}
p_m = math.fabs(p)
def code(p_m, x):
	return p_m / -x
p_m = abs(p)
function code(p_m, x)
	return Float64(p_m / Float64(-x))
end
p_m = abs(p);
function tmp = code(p_m, x)
	tmp = p_m / -x;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := N[(p$95$m / (-x)), $MachinePrecision]
\begin{array}{l}
p_m = \left|p\right|

\\
\frac{p\_m}{-x}
\end{array}
Derivation
  1. Initial program 79.2%

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  2. Step-by-step derivation
    1. +-commutative79.2%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} + 1\right)}} \]
    2. sqr-neg79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + \color{blue}{\left(-x\right) \cdot \left(-x\right)}}} + 1\right)} \]
    3. associate-*l*79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + \left(-x\right) \cdot \left(-x\right)}} + 1\right)} \]
    4. sqr-neg79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + \color{blue}{x \cdot x}}} + 1\right)} \]
    5. fma-define79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} + 1\right)} \]
    6. sqr-neg79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, \color{blue}{\left(-p\right) \cdot \left(-p\right)}, x \cdot x\right)}} + 1\right)} \]
    7. fma-define79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(\left(-p\right) \cdot \left(-p\right)\right) + x \cdot x}}} + 1\right)} \]
    8. associate-*l*79.2%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}} + 1\right)} \]
    9. +-commutative79.2%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(1 + \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}\right)}} \]
  3. Simplified79.2%

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

    \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
  6. Step-by-step derivation
    1. mul-1-neg18.1%

      \[\leadsto \color{blue}{-\frac{p}{x}} \]
    2. distribute-neg-frac218.1%

      \[\leadsto \color{blue}{\frac{p}{-x}} \]
  7. Simplified18.1%

    \[\leadsto \color{blue}{\frac{p}{-x}} \]
  8. Final simplification18.1%

    \[\leadsto \frac{p}{-x} \]
  9. Add Preprocessing

Developer target: 79.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}} \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x))))))
double code(double p, double x) {
	return sqrt((0.5 + (copysign(0.5, x) / hypot(1.0, ((2.0 * p) / x)))));
}
public static double code(double p, double x) {
	return Math.sqrt((0.5 + (Math.copySign(0.5, x) / Math.hypot(1.0, ((2.0 * p) / x)))));
}
def code(p, x):
	return math.sqrt((0.5 + (math.copysign(0.5, x) / math.hypot(1.0, ((2.0 * p) / x)))))
function code(p, x)
	return sqrt(Float64(0.5 + Float64(copysign(0.5, x) / hypot(1.0, Float64(Float64(2.0 * p) / x)))))
end
function tmp = code(p, x)
	tmp = sqrt((0.5 + ((sign(x) * abs(0.5)) / hypot(1.0, ((2.0 * p) / x)))));
end
code[p_, x_] := N[Sqrt[N[(0.5 + N[(N[With[{TMP1 = Abs[0.5], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + N[(N[(2.0 * p), $MachinePrecision] / x), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

Reproduce

?
herbie shell --seed 2024043 
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))

  :alt
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))