Given's Rotation SVD example

Percentage Accurate: 78.5% → 99.9%
Time: 11.3s
Alternatives: 7
Speedup: 0.7×

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 7 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: 78.5% 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.9% accurate, 0.5× 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.6:\\ \;\;\;\;3 \cdot \left({\left(\frac{p_m}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p_m \cdot 2, x\right)}\right)}\\ \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.6)
   (- (* 3.0 (* (pow (/ p_m x) 3.0) (/ (sqrt 0.5) (sqrt 2.0)))) (/ p_m x))
   (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p_m 2.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.6) {
		tmp = (3.0 * (pow((p_m / x), 3.0) * (sqrt(0.5) / sqrt(2.0)))) - (p_m / x);
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.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.6) {
		tmp = (3.0 * (Math.pow((p_m / x), 3.0) * (Math.sqrt(0.5) / Math.sqrt(2.0)))) - (p_m / x);
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p_m * 2.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.6:
		tmp = (3.0 * (math.pow((p_m / x), 3.0) * (math.sqrt(0.5) / math.sqrt(2.0)))) - (p_m / x)
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p_m * 2.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.6)
		tmp = Float64(Float64(3.0 * Float64((Float64(p_m / x) ^ 3.0) * Float64(sqrt(0.5) / sqrt(2.0)))) - Float64(p_m / x));
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p_m * 2.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.6)
		tmp = (3.0 * (((p_m / x) ^ 3.0) * (sqrt(0.5) / sqrt(2.0)))) - (p_m / x);
	else
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.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.6], N[(N[(3.0 * N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * N[(N[Sqrt[0.5], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p$95$m * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $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.6:\\
\;\;\;\;3 \cdot \left({\left(\frac{p_m}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p_m}{x}\\

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


\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.599999999999999978

    1. Initial program 14.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. add-sqr-sqrt14.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} + -0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} \]
    6. Step-by-step derivation
      1. +-commutative39.5%

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/39.5%

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

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \color{blue}{\left({p}^{4} \cdot \left(-4 + -2\right)\right)}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      7. metadata-eval48.5%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*48.5%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    7. Simplified48.5%

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 48.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} + 3 \cdot \frac{{p}^{3} \cdot \sqrt{0.5}}{{x}^{3} \cdot \sqrt{2}}} \]
    9. Step-by-step derivation
      1. +-commutative48.5%

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

        \[\leadsto 3 \cdot \frac{{p}^{3} \cdot \sqrt{0.5}}{{x}^{3} \cdot \sqrt{2}} + \color{blue}{\left(-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}\right)} \]
      3. unsub-neg48.5%

        \[\leadsto \color{blue}{3 \cdot \frac{{p}^{3} \cdot \sqrt{0.5}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. times-frac48.5%

        \[\leadsto 3 \cdot \color{blue}{\left(\frac{{p}^{3}}{{x}^{3}} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      5. cube-div52.3%

        \[\leadsto 3 \cdot \left(\color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      6. associate-/l*52.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      7. associate-/r*52.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified52.6%

      \[\leadsto \color{blue}{3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/52.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval52.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval52.3%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u22.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef3.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr3.6%

      \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def22.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
    14. Simplified53.2%

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

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

    1. Initial program 99.8%

      \[\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. add-sqr-sqrt99.8%

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

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

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

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

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

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

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

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

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

Alternative 2: 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.6:\\ \;\;\;\;\frac{-p_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p_m \cdot 2, x\right)}\right)}\\ \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.6)
   (/ (- p_m) x)
   (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p_m 2.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.6) {
		tmp = -p_m / x;
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.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.6) {
		tmp = -p_m / x;
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p_m * 2.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.6:
		tmp = -p_m / x
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p_m * 2.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.6)
		tmp = Float64(Float64(-p_m) / x);
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p_m * 2.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.6)
		tmp = -p_m / x;
	else
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.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.6], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p$95$m * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $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.6:\\
\;\;\;\;\frac{-p_m}{x}\\

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


\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.599999999999999978

    1. Initial program 14.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. add-sqr-sqrt14.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} + -0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} \]
    6. Step-by-step derivation
      1. +-commutative39.5%

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/39.5%

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

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \color{blue}{\left({p}^{4} \cdot \left(-4 + -2\right)\right)}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      7. metadata-eval48.5%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*48.5%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    7. Simplified48.5%

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 52.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg52.3%

        \[\leadsto \color{blue}{-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      2. associate-/l*52.3%

        \[\leadsto -\color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      3. distribute-neg-frac52.3%

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      4. associate-/r*52.5%

        \[\leadsto \frac{-p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified52.5%

      \[\leadsto \color{blue}{\frac{-p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/52.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval52.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval52.3%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u22.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef3.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr3.6%

      \[\leadsto \frac{-p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def22.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p53.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
    14. Simplified53.2%

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

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

    1. Initial program 99.8%

      \[\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. add-sqr-sqrt99.8%

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

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

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

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

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

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

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

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

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

Alternative 3: 68.7% accurate, 1.9× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;p_m \leq 3.6 \cdot 10^{-257}:\\ \;\;\;\;1\\ \mathbf{elif}\;p_m \leq 1.52 \cdot 10^{-238}:\\ \;\;\;\;\frac{-p_m}{x}\\ \mathbf{elif}\;p_m \leq 4 \cdot 10^{-40}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= p_m 3.6e-257)
   1.0
   (if (<= p_m 1.52e-238) (/ (- p_m) x) (if (<= p_m 4e-40) 1.0 (sqrt 0.5)))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (p_m <= 3.6e-257) {
		tmp = 1.0;
	} else if (p_m <= 1.52e-238) {
		tmp = -p_m / x;
	} else if (p_m <= 4e-40) {
		tmp = 1.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) :: tmp
    if (p_m <= 3.6d-257) then
        tmp = 1.0d0
    else if (p_m <= 1.52d-238) then
        tmp = -p_m / x
    else if (p_m <= 4d-40) then
        tmp = 1.0d0
    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 tmp;
	if (p_m <= 3.6e-257) {
		tmp = 1.0;
	} else if (p_m <= 1.52e-238) {
		tmp = -p_m / x;
	} else if (p_m <= 4e-40) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if p_m <= 3.6e-257:
		tmp = 1.0
	elif p_m <= 1.52e-238:
		tmp = -p_m / x
	elif p_m <= 4e-40:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (p_m <= 3.6e-257)
		tmp = 1.0;
	elseif (p_m <= 1.52e-238)
		tmp = Float64(Float64(-p_m) / x);
	elseif (p_m <= 4e-40)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (p_m <= 3.6e-257)
		tmp = 1.0;
	elseif (p_m <= 1.52e-238)
		tmp = -p_m / x;
	elseif (p_m <= 4e-40)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[p$95$m, 3.6e-257], 1.0, If[LessEqual[p$95$m, 1.52e-238], N[((-p$95$m) / x), $MachinePrecision], If[LessEqual[p$95$m, 4e-40], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;p_m \leq 3.6 \cdot 10^{-257}:\\
\;\;\;\;1\\

\mathbf{elif}\;p_m \leq 1.52 \cdot 10^{-238}:\\
\;\;\;\;\frac{-p_m}{x}\\

\mathbf{elif}\;p_m \leq 4 \cdot 10^{-40}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 3.60000000000000007e-257 or 1.5200000000000001e-238 < p < 3.9999999999999997e-40

    1. Initial program 77.1%

      \[\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 inf 44.4%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{2}} \]

    if 3.60000000000000007e-257 < p < 1.5200000000000001e-238

    1. Initial program 36.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. add-sqr-sqrt36.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/33.3%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      5. times-frac65.8%

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \color{blue}{\left({p}^{4} \cdot \left(-4 + -2\right)\right)}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      7. metadata-eval65.8%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*66.1%

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

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 98.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg98.3%

        \[\leadsto \color{blue}{-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      2. associate-/l*99.0%

        \[\leadsto -\color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      3. distribute-neg-frac99.0%

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      4. associate-/r*99.0%

        \[\leadsto \frac{-p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified99.0%

      \[\leadsto \color{blue}{\frac{-p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/99.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval99.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval99.0%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity100.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u66.7%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef0.7%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr0.7%

      \[\leadsto \frac{-p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def66.7%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p100.0%

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

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

    if 3.9999999999999997e-40 < p

    1. Initial program 92.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. Taylor expanded in x around 0 86.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 3.6 \cdot 10^{-257}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.52 \cdot 10^{-238}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 4 \cdot 10^{-40}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 68.9% accurate, 2.0× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;p_m \leq 1.5 \cdot 10^{-82}:\\ \;\;\;\;\frac{-p_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= p_m 1.5e-82) (/ (- p_m) x) (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (p_m <= 1.5e-82) {
		tmp = -p_m / x;
	} 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) :: tmp
    if (p_m <= 1.5d-82) then
        tmp = -p_m / x
    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 tmp;
	if (p_m <= 1.5e-82) {
		tmp = -p_m / x;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if p_m <= 1.5e-82:
		tmp = -p_m / x
	else:
		tmp = math.sqrt(0.5)
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (p_m <= 1.5e-82)
		tmp = Float64(Float64(-p_m) / x);
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (p_m <= 1.5e-82)
		tmp = -p_m / x;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[p$95$m, 1.5e-82], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;p_m \leq 1.5 \cdot 10^{-82}:\\
\;\;\;\;\frac{-p_m}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if p < 1.4999999999999999e-82

    1. Initial program 74.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. add-sqr-sqrt74.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} + -0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} \]
    6. Step-by-step derivation
      1. +-commutative10.8%

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/10.8%

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

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

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*14.2%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    7. Simplified14.2%

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 16.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg16.4%

        \[\leadsto \color{blue}{-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      2. associate-/l*16.4%

        \[\leadsto -\color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      3. distribute-neg-frac16.4%

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      4. associate-/r*16.4%

        \[\leadsto \frac{-p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified16.4%

      \[\leadsto \color{blue}{\frac{-p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/16.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval16.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval16.0%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u8.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef2.3%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr2.9%

      \[\leadsto \frac{-p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def8.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p16.2%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
    14. Simplified16.6%

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

    if 1.4999999999999999e-82 < p

    1. Initial program 93.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. Taylor expanded in x around 0 82.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.5 \cdot 10^{-82}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 29.6% accurate, 21.5× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{-p_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{p_m}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= x -5e-310) (/ (- p_m) x) (/ 1.0 (/ x p_m))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -p_m / x;
	} else {
		tmp = 1.0 / (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 (x <= (-5d-310)) then
        tmp = -p_m / x
    else
        tmp = 1.0d0 / (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 (x <= -5e-310) {
		tmp = -p_m / x;
	} else {
		tmp = 1.0 / (x / p_m);
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if x <= -5e-310:
		tmp = -p_m / x
	else:
		tmp = 1.0 / (x / p_m)
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(Float64(-p_m) / x);
	else
		tmp = Float64(1.0 / Float64(x / p_m));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (x <= -5e-310)
		tmp = -p_m / x;
	else
		tmp = 1.0 / (x / p_m);
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[x, -5e-310], N[((-p$95$m) / x), $MachinePrecision], N[(1.0 / N[(x / p$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-p_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x}{p_m}}\\


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

    1. Initial program 61.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. add-sqr-sqrt61.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/18.4%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      5. times-frac22.8%

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \color{blue}{\left({p}^{4} \cdot \left(-4 + -2\right)\right)}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      7. metadata-eval22.8%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*22.8%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    7. Simplified22.8%

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 25.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg25.4%

        \[\leadsto \color{blue}{-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      2. associate-/l*25.4%

        \[\leadsto -\color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      3. distribute-neg-frac25.4%

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      4. associate-/r*25.5%

        \[\leadsto \frac{-p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified25.5%

      \[\leadsto \color{blue}{\frac{-p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/24.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval24.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval24.6%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u10.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef2.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr2.3%

      \[\leadsto \frac{-p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def10.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
    14. Simplified25.8%

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

    if -4.999999999999985e-310 < x

    1. Initial program 99.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. +-commutative99.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. add-cube-cbrt99.7%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg1.8%

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}} \]
      2. distribute-rgt-neg-in1.8%

        \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
      3. distribute-rgt-out1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{p}^{2} \cdot \left(0.6666666666666666 + 1.3333333333333333\right)}}\right) \]
      4. metadata-eval1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{2}}\right) \]
      5. rem-square-sqrt1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}}\right) \]
      6. unpow21.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{{\left(\sqrt{2}\right)}^{2}}}\right) \]
      7. *-commutative1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{\left(\sqrt{2}\right)}^{2} \cdot {p}^{2}}}\right) \]
      8. unpow21.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)} \cdot {p}^{2}}\right) \]
      9. rem-square-sqrt1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{2} \cdot {p}^{2}}\right) \]
    7. Simplified1.8%

      \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{2 \cdot {p}^{2}}\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt0.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{2 \cdot {p}^{2}}} \cdot \sqrt{-\sqrt{2 \cdot {p}^{2}}}\right)} \]
      2. sqrt-unprod4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\sqrt{\left(-\sqrt{2 \cdot {p}^{2}}\right) \cdot \left(-\sqrt{2 \cdot {p}^{2}}\right)}} \]
      3. sqr-neg4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{\sqrt{2 \cdot {p}^{2}} \cdot \sqrt{2 \cdot {p}^{2}}}} \]
      4. add-sqr-sqrt4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{2 \cdot {p}^{2}}} \]
      5. sqrt-unprod4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{{p}^{2}}\right)} \]
      6. unpow24.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \sqrt{\color{blue}{p \cdot p}}\right) \]
      7. sqrt-prod3.0%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)}\right) \]
      8. add-sqr-sqrt3.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \color{blue}{p}\right) \]
      9. associate-*r*3.6%

        \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{2}\right) \cdot p} \]
      10. clear-num3.6%

        \[\leadsto \left(\color{blue}{\frac{1}{\frac{x}{\sqrt{0.5}}}} \cdot \sqrt{2}\right) \cdot p \]
      11. associate-/r/3.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \cdot p \]
      12. associate-/r/3.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}{p}}} \]
      13. clear-num3.6%

        \[\leadsto \color{blue}{\frac{p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
      14. clear-num3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{1}{\frac{\sqrt{2}}{\frac{x}{\sqrt{0.5}}}}}} \]
      15. clear-num3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
      16. associate-/l/3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
    9. Applied egg-rr3.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{p}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 29.6% accurate, 23.8× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{-p_m}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{p_m}{x}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= x -5e-310) (/ (- p_m) x) (/ p_m x)))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -p_m / x;
	} else {
		tmp = 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 <= (-5d-310)) then
        tmp = -p_m / x
    else
        tmp = 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 <= -5e-310) {
		tmp = -p_m / x;
	} else {
		tmp = p_m / x;
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if x <= -5e-310:
		tmp = -p_m / x
	else:
		tmp = p_m / x
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(Float64(-p_m) / x);
	else
		tmp = Float64(p_m / x);
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if (x <= -5e-310)
		tmp = -p_m / x;
	else
		tmp = p_m / x;
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[x, -5e-310], N[((-p$95$m) / x), $MachinePrecision], N[(p$95$m / x), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-p_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{p_m}{x}\\


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

    1. Initial program 61.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. add-sqr-sqrt61.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-0.5 \cdot \frac{\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      4. associate-*r/18.4%

        \[\leadsto \color{blue}{\frac{-0.5 \cdot \left(\sqrt{0.5} \cdot \left(-4 \cdot {p}^{4} + -2 \cdot {p}^{4}\right)\right)}{p \cdot \left({x}^{3} \cdot \sqrt{2}\right)}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      5. times-frac22.8%

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

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \color{blue}{\left({p}^{4} \cdot \left(-4 + -2\right)\right)}}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      7. metadata-eval22.8%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot \color{blue}{-6}\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x} \]
      8. associate-/l*22.8%

        \[\leadsto \frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    7. Simplified22.8%

      \[\leadsto \color{blue}{\frac{-0.5}{p} \cdot \frac{\sqrt{0.5} \cdot \left({p}^{4} \cdot -6\right)}{{x}^{3} \cdot \sqrt{2}} - \frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
    8. Taylor expanded in p around 0 25.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg25.4%

        \[\leadsto \color{blue}{-\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{x}} \]
      2. associate-/l*25.4%

        \[\leadsto -\color{blue}{\frac{p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      3. distribute-neg-frac25.4%

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{0.5} \cdot \sqrt{2}}}} \]
      4. associate-/r*25.5%

        \[\leadsto \frac{-p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    10. Simplified25.5%

      \[\leadsto \color{blue}{\frac{-p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    11. Step-by-step derivation
      1. associate-/l/24.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
      2. metadata-eval24.6%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\sqrt{0.25}}}}} \]
      3. metadata-eval24.6%

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

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2} \cdot \sqrt{\color{blue}{\frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      5. sqrt-unprod25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{\sqrt{2 \cdot \frac{\sqrt{0.5}}{\sqrt{2}}}}}} \]
      6. sqrt-undiv25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{\sqrt{\frac{0.5}{2}}}}}} \]
      7. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \sqrt{\color{blue}{0.25}}}}} \]
      8. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{2 \cdot \color{blue}{0.5}}}} \]
      9. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\sqrt{\color{blue}{1}}}} \]
      10. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\frac{x}{\color{blue}{1}}} \]
      11. div-inv25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x \cdot \frac{1}{1}}} \]
      12. metadata-eval25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{x \cdot \color{blue}{1}} \]
      13. *-commutative25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{1 \cdot x}} \]
      14. *-un-lft-identity25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
      15. expm1-log1p-u10.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      16. expm1-udef2.1%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    12. Applied egg-rr2.3%

      \[\leadsto \frac{-p}{\color{blue}{e^{\mathsf{log1p}\left(x\right)} - 1}} \]
    13. Step-by-step derivation
      1. expm1-def10.5%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)}} \]
      2. expm1-log1p25.0%

        \[\leadsto 3 \cdot \left({\left(\frac{p}{x}\right)}^{3} \cdot \frac{\sqrt{0.5}}{\sqrt{2}}\right) - \frac{p}{\color{blue}{x}} \]
    14. Simplified25.8%

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

    if -4.999999999999985e-310 < x

    1. Initial program 99.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. +-commutative99.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. add-cube-cbrt99.7%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg1.8%

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}} \]
      2. distribute-rgt-neg-in1.8%

        \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
      3. distribute-rgt-out1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{p}^{2} \cdot \left(0.6666666666666666 + 1.3333333333333333\right)}}\right) \]
      4. metadata-eval1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{2}}\right) \]
      5. rem-square-sqrt1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}}\right) \]
      6. unpow21.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{{\left(\sqrt{2}\right)}^{2}}}\right) \]
      7. *-commutative1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{\left(\sqrt{2}\right)}^{2} \cdot {p}^{2}}}\right) \]
      8. unpow21.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)} \cdot {p}^{2}}\right) \]
      9. rem-square-sqrt1.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{2} \cdot {p}^{2}}\right) \]
    7. Simplified1.8%

      \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{2 \cdot {p}^{2}}\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt0.8%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{2 \cdot {p}^{2}}} \cdot \sqrt{-\sqrt{2 \cdot {p}^{2}}}\right)} \]
      2. sqrt-unprod4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\sqrt{\left(-\sqrt{2 \cdot {p}^{2}}\right) \cdot \left(-\sqrt{2 \cdot {p}^{2}}\right)}} \]
      3. sqr-neg4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{\sqrt{2 \cdot {p}^{2}} \cdot \sqrt{2 \cdot {p}^{2}}}} \]
      4. add-sqr-sqrt4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{2 \cdot {p}^{2}}} \]
      5. sqrt-unprod4.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{{p}^{2}}\right)} \]
      6. unpow24.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \sqrt{\color{blue}{p \cdot p}}\right) \]
      7. sqrt-prod3.0%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)}\right) \]
      8. add-sqr-sqrt3.6%

        \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \color{blue}{p}\right) \]
      9. associate-*r*3.6%

        \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{2}\right) \cdot p} \]
      10. clear-num3.6%

        \[\leadsto \left(\color{blue}{\frac{1}{\frac{x}{\sqrt{0.5}}}} \cdot \sqrt{2}\right) \cdot p \]
      11. associate-/r/3.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \cdot p \]
      12. associate-/r/3.6%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}{p}}} \]
      13. clear-num3.6%

        \[\leadsto \color{blue}{\frac{p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
      14. clear-num3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{1}{\frac{\sqrt{2}}{\frac{x}{\sqrt{0.5}}}}}} \]
      15. clear-num3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
      16. associate-/l/3.6%

        \[\leadsto \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
    9. Applied egg-rr3.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{p}{x}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def3.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{p}{x}\right)\right)} \]
      2. expm1-log1p3.6%

        \[\leadsto \color{blue}{\frac{p}{x}} \]
    11. Simplified3.6%

      \[\leadsto \color{blue}{\frac{p}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{p}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 6.6% accurate, 71.7× 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 / 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 81.1%

    \[\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. +-commutative81.1%

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
  6. Step-by-step derivation
    1. mul-1-neg14.4%

      \[\leadsto \color{blue}{-\frac{\sqrt{0.5}}{x} \cdot \sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}} \]
    2. distribute-rgt-neg-in14.4%

      \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{0.6666666666666666 \cdot {p}^{2} + 1.3333333333333333 \cdot {p}^{2}}\right)} \]
    3. distribute-rgt-out14.4%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{p}^{2} \cdot \left(0.6666666666666666 + 1.3333333333333333\right)}}\right) \]
    4. metadata-eval14.4%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{2}}\right) \]
    5. rem-square-sqrt14.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)}}\right) \]
    6. unpow214.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{{p}^{2} \cdot \color{blue}{{\left(\sqrt{2}\right)}^{2}}}\right) \]
    7. *-commutative14.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{{\left(\sqrt{2}\right)}^{2} \cdot {p}^{2}}}\right) \]
    8. unpow214.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right)} \cdot {p}^{2}}\right) \]
    9. rem-square-sqrt14.4%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{\color{blue}{2} \cdot {p}^{2}}\right) \]
  7. Simplified14.4%

    \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{x} \cdot \left(-\sqrt{2 \cdot {p}^{2}}\right)} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt2.8%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{2 \cdot {p}^{2}}} \cdot \sqrt{-\sqrt{2 \cdot {p}^{2}}}\right)} \]
    2. sqrt-unprod5.3%

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

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{\sqrt{2 \cdot {p}^{2}} \cdot \sqrt{2 \cdot {p}^{2}}}} \]
    4. add-sqr-sqrt5.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \sqrt{\color{blue}{2 \cdot {p}^{2}}} \]
    5. sqrt-unprod5.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{{p}^{2}}\right)} \]
    6. unpow25.3%

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \sqrt{\color{blue}{p \cdot p}}\right) \]
    7. sqrt-prod3.5%

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

      \[\leadsto \frac{\sqrt{0.5}}{x} \cdot \left(\sqrt{2} \cdot \color{blue}{p}\right) \]
    9. associate-*r*15.1%

      \[\leadsto \color{blue}{\left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{2}\right) \cdot p} \]
    10. clear-num15.1%

      \[\leadsto \left(\color{blue}{\frac{1}{\frac{x}{\sqrt{0.5}}}} \cdot \sqrt{2}\right) \cdot p \]
    11. associate-/r/15.1%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \cdot p \]
    12. associate-/r/15.1%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}{p}}} \]
    13. clear-num15.1%

      \[\leadsto \color{blue}{\frac{p}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    14. clear-num15.1%

      \[\leadsto \frac{p}{\color{blue}{\frac{1}{\frac{\sqrt{2}}{\frac{x}{\sqrt{0.5}}}}}} \]
    15. clear-num15.1%

      \[\leadsto \frac{p}{\color{blue}{\frac{\frac{x}{\sqrt{0.5}}}{\sqrt{2}}}} \]
    16. associate-/l/15.0%

      \[\leadsto \frac{p}{\color{blue}{\frac{x}{\sqrt{2} \cdot \sqrt{0.5}}}} \]
  9. Applied egg-rr5.5%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{p}{x}\right)} - 1} \]
  10. Step-by-step derivation
    1. expm1-def15.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{p}{x}\right)\right)} \]
    2. expm1-log1p15.2%

      \[\leadsto \color{blue}{\frac{p}{x}} \]
  11. Simplified15.2%

    \[\leadsto \color{blue}{\frac{p}{x}} \]
  12. Final simplification15.2%

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

Developer target: 78.5% 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 2024020 
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))

  :herbie-target
  (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))))))))