Given's Rotation SVD example

Percentage Accurate: 79.7% → 99.7%
Time: 8.2s
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: 79.7% 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.7% accurate, 0.7× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.5:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.5)
   (/ (- p) x)
   (sqrt (+ 0.5 (* x (/ 0.5 (hypot x (* p 2.0))))))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
		tmp = -p / x;
	} else {
		tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0))))));
	}
	return tmp;
}
p = Math.abs(p);
public static double code(double p, double x) {
	double tmp;
	if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
		tmp = -p / x;
	} else {
		tmp = Math.sqrt((0.5 + (x * (0.5 / Math.hypot(x, (p * 2.0))))));
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5:
		tmp = -p / x
	else:
		tmp = math.sqrt((0.5 + (x * (0.5 / math.hypot(x, (p * 2.0))))))
	return tmp
p = abs(p)
function code(p, x)
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.5)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.5 / hypot(x, Float64(p * 2.0))))));
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	tmp = 0.0;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5)
		tmp = -p / x;
	else
		tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0))))));
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 + N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.5:\\
\;\;\;\;\frac{-p}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\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.5

    1. Initial program 14.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    8. Simplified54.4%

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

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

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def99.0%

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

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

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

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

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

Alternative 2: 66.7% accurate, 1.0× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} t_0 := p \cdot \sqrt{{x}^{-2}}\\ t_1 := \frac{-p}{x}\\ t_2 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{if}\;p \leq 3.8 \cdot 10^{-246}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;p \leq 2.55 \cdot 10^{-228}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;p \leq 2.3 \cdot 10^{-165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 5.4 \cdot 10^{-132}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;p \leq 7.5 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 920000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 2.55 \cdot 10^{+64}:\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.25}{p}}\\ \mathbf{elif}\;p \leq 2.6 \cdot 10^{+67}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (* p (sqrt (pow x -2.0))))
        (t_1 (/ (- p) x))
        (t_2 (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
   (if (<= p 3.8e-246)
     t_1
     (if (<= p 2.55e-228)
       t_2
       (if (<= p 2.3e-165)
         t_0
         (if (<= p 5.4e-132)
           t_2
           (if (<= p 7.5e-66)
             t_0
             (if (<= p 920000000000.0)
               1.0
               (if (<= p 2.55e+64)
                 (sqrt (+ 0.5 (* x (/ 0.25 p))))
                 (if (<= p 2.6e+67) t_1 (sqrt 0.5)))))))))))
p = abs(p);
double code(double p, double x) {
	double t_0 = p * sqrt(pow(x, -2.0));
	double t_1 = -p / x;
	double t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	double tmp;
	if (p <= 3.8e-246) {
		tmp = t_1;
	} else if (p <= 2.55e-228) {
		tmp = t_2;
	} else if (p <= 2.3e-165) {
		tmp = t_0;
	} else if (p <= 5.4e-132) {
		tmp = t_2;
	} else if (p <= 7.5e-66) {
		tmp = t_0;
	} else if (p <= 920000000000.0) {
		tmp = 1.0;
	} else if (p <= 2.55e+64) {
		tmp = sqrt((0.5 + (x * (0.25 / p))));
	} else if (p <= 2.6e+67) {
		tmp = t_1;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = p * sqrt((x ** (-2.0d0)))
    t_1 = -p / x
    t_2 = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
    if (p <= 3.8d-246) then
        tmp = t_1
    else if (p <= 2.55d-228) then
        tmp = t_2
    else if (p <= 2.3d-165) then
        tmp = t_0
    else if (p <= 5.4d-132) then
        tmp = t_2
    else if (p <= 7.5d-66) then
        tmp = t_0
    else if (p <= 920000000000.0d0) then
        tmp = 1.0d0
    else if (p <= 2.55d+64) then
        tmp = sqrt((0.5d0 + (x * (0.25d0 / p))))
    else if (p <= 2.6d+67) then
        tmp = t_1
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double t_0 = p * Math.sqrt(Math.pow(x, -2.0));
	double t_1 = -p / x;
	double t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	double tmp;
	if (p <= 3.8e-246) {
		tmp = t_1;
	} else if (p <= 2.55e-228) {
		tmp = t_2;
	} else if (p <= 2.3e-165) {
		tmp = t_0;
	} else if (p <= 5.4e-132) {
		tmp = t_2;
	} else if (p <= 7.5e-66) {
		tmp = t_0;
	} else if (p <= 920000000000.0) {
		tmp = 1.0;
	} else if (p <= 2.55e+64) {
		tmp = Math.sqrt((0.5 + (x * (0.25 / p))));
	} else if (p <= 2.6e+67) {
		tmp = t_1;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	t_0 = p * math.sqrt(math.pow(x, -2.0))
	t_1 = -p / x
	t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)))
	tmp = 0
	if p <= 3.8e-246:
		tmp = t_1
	elif p <= 2.55e-228:
		tmp = t_2
	elif p <= 2.3e-165:
		tmp = t_0
	elif p <= 5.4e-132:
		tmp = t_2
	elif p <= 7.5e-66:
		tmp = t_0
	elif p <= 920000000000.0:
		tmp = 1.0
	elif p <= 2.55e+64:
		tmp = math.sqrt((0.5 + (x * (0.25 / p))))
	elif p <= 2.6e+67:
		tmp = t_1
	else:
		tmp = math.sqrt(0.5)
	return tmp
p = abs(p)
function code(p, x)
	t_0 = Float64(p * sqrt((x ^ -2.0)))
	t_1 = Float64(Float64(-p) / x)
	t_2 = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x))))
	tmp = 0.0
	if (p <= 3.8e-246)
		tmp = t_1;
	elseif (p <= 2.55e-228)
		tmp = t_2;
	elseif (p <= 2.3e-165)
		tmp = t_0;
	elseif (p <= 5.4e-132)
		tmp = t_2;
	elseif (p <= 7.5e-66)
		tmp = t_0;
	elseif (p <= 920000000000.0)
		tmp = 1.0;
	elseif (p <= 2.55e+64)
		tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.25 / p))));
	elseif (p <= 2.6e+67)
		tmp = t_1;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	t_0 = p * sqrt((x ^ -2.0));
	t_1 = -p / x;
	t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	tmp = 0.0;
	if (p <= 3.8e-246)
		tmp = t_1;
	elseif (p <= 2.55e-228)
		tmp = t_2;
	elseif (p <= 2.3e-165)
		tmp = t_0;
	elseif (p <= 5.4e-132)
		tmp = t_2;
	elseif (p <= 7.5e-66)
		tmp = t_0;
	elseif (p <= 920000000000.0)
		tmp = 1.0;
	elseif (p <= 2.55e+64)
		tmp = sqrt((0.5 + (x * (0.25 / p))));
	elseif (p <= 2.6e+67)
		tmp = t_1;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[(p * N[Sqrt[N[Power[x, -2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-p) / x), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, 3.8e-246], t$95$1, If[LessEqual[p, 2.55e-228], t$95$2, If[LessEqual[p, 2.3e-165], t$95$0, If[LessEqual[p, 5.4e-132], t$95$2, If[LessEqual[p, 7.5e-66], t$95$0, If[LessEqual[p, 920000000000.0], 1.0, If[LessEqual[p, 2.55e+64], N[Sqrt[N[(0.5 + N[(x * N[(0.25 / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[p, 2.6e+67], t$95$1, N[Sqrt[0.5], $MachinePrecision]]]]]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := p \cdot \sqrt{{x}^{-2}}\\
t_1 := \frac{-p}{x}\\
t_2 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\mathbf{if}\;p \leq 3.8 \cdot 10^{-246}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;p \leq 2.55 \cdot 10^{-228}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;p \leq 2.3 \cdot 10^{-165}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 5.4 \cdot 10^{-132}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;p \leq 7.5 \cdot 10^{-66}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 920000000000:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 2.55 \cdot 10^{+64}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.25}{p}}\\

\mathbf{elif}\;p \leq 2.6 \cdot 10^{+67}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if p < 3.79999999999999976e-246 or 2.55000000000000012e64 < p < 2.6e67

    1. Initial program 73.7%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def72.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)\right)} \]
      2. expm1-log1p73.7%

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    8. Simplified11.9%

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

    if 3.79999999999999976e-246 < p < 2.5500000000000001e-228 or 2.3e-165 < p < 5.3999999999999998e-132

    1. Initial program 78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5500000000000001e-228 < p < 2.3e-165 or 5.3999999999999998e-132 < p < 7.49999999999999995e-66

    1. Initial program 47.5%

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\left(e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} - 1\right)}\right)} \]
      4. add-exp-log47.5%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{{p}^{2}}{{x}^{2}}}} \]
    5. Step-by-step derivation
      1. div-inv16.9%

        \[\leadsto \sqrt{\color{blue}{{p}^{2} \cdot \frac{1}{{x}^{2}}}} \]
      2. sqrt-prod41.5%

        \[\leadsto \color{blue}{\sqrt{{p}^{2}} \cdot \sqrt{\frac{1}{{x}^{2}}}} \]
      3. unpow241.5%

        \[\leadsto \sqrt{\color{blue}{p \cdot p}} \cdot \sqrt{\frac{1}{{x}^{2}}} \]
      4. sqrt-prod59.2%

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

        \[\leadsto \color{blue}{p} \cdot \sqrt{\frac{1}{{x}^{2}}} \]
      6. *-commutative59.2%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{{x}^{2}}} \cdot p} \]
      7. pow-flip59.2%

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

        \[\leadsto \sqrt{{x}^{\color{blue}{-2}}} \cdot p \]
    6. Applied egg-rr59.2%

      \[\leadsto \color{blue}{\sqrt{{x}^{-2}} \cdot p} \]

    if 7.49999999999999995e-66 < p < 9.2e11

    1. Initial program 83.9%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Taylor expanded in x around inf 62.3%

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

    if 9.2e11 < p < 2.55000000000000012e64

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 + \color{blue}{\frac{0.25}{p}} \cdot x} \]

    if 2.6e67 < p

    1. Initial program 97.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 3.8 \cdot 10^{-246}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 2.55 \cdot 10^{-228}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 2.3 \cdot 10^{-165}:\\ \;\;\;\;p \cdot \sqrt{{x}^{-2}}\\ \mathbf{elif}\;p \leq 5.4 \cdot 10^{-132}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 7.5 \cdot 10^{-66}:\\ \;\;\;\;p \cdot \sqrt{{x}^{-2}}\\ \mathbf{elif}\;p \leq 920000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 2.55 \cdot 10^{+64}:\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.25}{p}}\\ \mathbf{elif}\;p \leq 2.6 \cdot 10^{+67}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 3: 67.5% accurate, 1.9× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} t_0 := \frac{-p}{x}\\ \mathbf{if}\;p \leq 5.2 \cdot 10^{-243}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 7.8 \cdot 10^{-227}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 4.7 \cdot 10^{-163}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 1.02 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 7 \cdot 10^{-67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 6800000000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ (- p) x)))
   (if (<= p 5.2e-243)
     t_0
     (if (<= p 7.8e-227)
       (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))
       (if (<= p 4.7e-163)
         t_0
         (if (<= p 1.02e-80)
           1.0
           (if (<= p 7e-67) t_0 (if (<= p 6800000000.0) 1.0 (sqrt 0.5)))))))))
p = abs(p);
double code(double p, double x) {
	double t_0 = -p / x;
	double tmp;
	if (p <= 5.2e-243) {
		tmp = t_0;
	} else if (p <= 7.8e-227) {
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	} else if (p <= 4.7e-163) {
		tmp = t_0;
	} else if (p <= 1.02e-80) {
		tmp = 1.0;
	} else if (p <= 7e-67) {
		tmp = t_0;
	} else if (p <= 6800000000.0) {
		tmp = 1.0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -p / x
    if (p <= 5.2d-243) then
        tmp = t_0
    else if (p <= 7.8d-227) then
        tmp = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
    else if (p <= 4.7d-163) then
        tmp = t_0
    else if (p <= 1.02d-80) then
        tmp = 1.0d0
    else if (p <= 7d-67) then
        tmp = t_0
    else if (p <= 6800000000.0d0) then
        tmp = 1.0d0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double t_0 = -p / x;
	double tmp;
	if (p <= 5.2e-243) {
		tmp = t_0;
	} else if (p <= 7.8e-227) {
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	} else if (p <= 4.7e-163) {
		tmp = t_0;
	} else if (p <= 1.02e-80) {
		tmp = 1.0;
	} else if (p <= 7e-67) {
		tmp = t_0;
	} else if (p <= 6800000000.0) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	t_0 = -p / x
	tmp = 0
	if p <= 5.2e-243:
		tmp = t_0
	elif p <= 7.8e-227:
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)))
	elif p <= 4.7e-163:
		tmp = t_0
	elif p <= 1.02e-80:
		tmp = 1.0
	elif p <= 7e-67:
		tmp = t_0
	elif p <= 6800000000.0:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
p = abs(p)
function code(p, x)
	t_0 = Float64(Float64(-p) / x)
	tmp = 0.0
	if (p <= 5.2e-243)
		tmp = t_0;
	elseif (p <= 7.8e-227)
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x))));
	elseif (p <= 4.7e-163)
		tmp = t_0;
	elseif (p <= 1.02e-80)
		tmp = 1.0;
	elseif (p <= 7e-67)
		tmp = t_0;
	elseif (p <= 6800000000.0)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	t_0 = -p / x;
	tmp = 0.0;
	if (p <= 5.2e-243)
		tmp = t_0;
	elseif (p <= 7.8e-227)
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	elseif (p <= 4.7e-163)
		tmp = t_0;
	elseif (p <= 1.02e-80)
		tmp = 1.0;
	elseif (p <= 7e-67)
		tmp = t_0;
	elseif (p <= 6800000000.0)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[((-p) / x), $MachinePrecision]}, If[LessEqual[p, 5.2e-243], t$95$0, If[LessEqual[p, 7.8e-227], N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p, 4.7e-163], t$95$0, If[LessEqual[p, 1.02e-80], 1.0, If[LessEqual[p, 7e-67], t$95$0, If[LessEqual[p, 6800000000.0], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 5.2 \cdot 10^{-243}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;p \leq 4.7 \cdot 10^{-163}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 1.02 \cdot 10^{-80}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 7 \cdot 10^{-67}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 6800000000:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 5.1999999999999995e-243 or 7.7999999999999999e-227 < p < 4.7e-163 or 1.02000000000000005e-80 < p < 7.0000000000000001e-67

    1. Initial program 70.6%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def69.9%

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

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

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

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

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

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

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

    if 5.1999999999999995e-243 < p < 7.7999999999999999e-227

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def100.0%

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

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

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

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

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

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

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

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

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

    if 4.7e-163 < p < 1.02000000000000005e-80 or 7.0000000000000001e-67 < p < 6.8e9

    1. Initial program 72.3%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Taylor expanded in x around inf 58.5%

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

    if 6.8e9 < p

    1. Initial program 91.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 5.2 \cdot 10^{-243}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 7.8 \cdot 10^{-227}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 4.7 \cdot 10^{-163}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 1.02 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 7 \cdot 10^{-67}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 6800000000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 4: 68.0% accurate, 1.9× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} t_0 := \frac{-p}{x}\\ t_1 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{if}\;p \leq 3.6 \cdot 10^{-244}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 3.8 \cdot 10^{-228}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;p \leq 7.6 \cdot 10^{-166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 8.5 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;p \leq 1.4 \cdot 10^{-64}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ (- p) x)) (t_1 (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
   (if (<= p 3.6e-244)
     t_0
     (if (<= p 3.8e-228)
       t_1
       (if (<= p 7.6e-166)
         t_0
         (if (<= p 8.5e-85) t_1 (if (<= p 1.4e-64) t_0 (sqrt 0.5))))))))
p = abs(p);
double code(double p, double x) {
	double t_0 = -p / x;
	double t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	double tmp;
	if (p <= 3.6e-244) {
		tmp = t_0;
	} else if (p <= 3.8e-228) {
		tmp = t_1;
	} else if (p <= 7.6e-166) {
		tmp = t_0;
	} else if (p <= 8.5e-85) {
		tmp = t_1;
	} else if (p <= 1.4e-64) {
		tmp = t_0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -p / x
    t_1 = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
    if (p <= 3.6d-244) then
        tmp = t_0
    else if (p <= 3.8d-228) then
        tmp = t_1
    else if (p <= 7.6d-166) then
        tmp = t_0
    else if (p <= 8.5d-85) then
        tmp = t_1
    else if (p <= 1.4d-64) then
        tmp = t_0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double t_0 = -p / x;
	double t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	double tmp;
	if (p <= 3.6e-244) {
		tmp = t_0;
	} else if (p <= 3.8e-228) {
		tmp = t_1;
	} else if (p <= 7.6e-166) {
		tmp = t_0;
	} else if (p <= 8.5e-85) {
		tmp = t_1;
	} else if (p <= 1.4e-64) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	t_0 = -p / x
	t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)))
	tmp = 0
	if p <= 3.6e-244:
		tmp = t_0
	elif p <= 3.8e-228:
		tmp = t_1
	elif p <= 7.6e-166:
		tmp = t_0
	elif p <= 8.5e-85:
		tmp = t_1
	elif p <= 1.4e-64:
		tmp = t_0
	else:
		tmp = math.sqrt(0.5)
	return tmp
p = abs(p)
function code(p, x)
	t_0 = Float64(Float64(-p) / x)
	t_1 = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x))))
	tmp = 0.0
	if (p <= 3.6e-244)
		tmp = t_0;
	elseif (p <= 3.8e-228)
		tmp = t_1;
	elseif (p <= 7.6e-166)
		tmp = t_0;
	elseif (p <= 8.5e-85)
		tmp = t_1;
	elseif (p <= 1.4e-64)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	t_0 = -p / x;
	t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)));
	tmp = 0.0;
	if (p <= 3.6e-244)
		tmp = t_0;
	elseif (p <= 3.8e-228)
		tmp = t_1;
	elseif (p <= 7.6e-166)
		tmp = t_0;
	elseif (p <= 8.5e-85)
		tmp = t_1;
	elseif (p <= 1.4e-64)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[((-p) / x), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, 3.6e-244], t$95$0, If[LessEqual[p, 3.8e-228], t$95$1, If[LessEqual[p, 7.6e-166], t$95$0, If[LessEqual[p, 8.5e-85], t$95$1, If[LessEqual[p, 1.4e-64], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
t_1 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\mathbf{if}\;p \leq 3.6 \cdot 10^{-244}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 3.8 \cdot 10^{-228}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;p \leq 7.6 \cdot 10^{-166}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 8.5 \cdot 10^{-85}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;p \leq 1.4 \cdot 10^{-64}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 3.59999999999999975e-244 or 3.7999999999999999e-228 < p < 7.59999999999999964e-166 or 8.50000000000000052e-85 < p < 1.40000000000000002e-64

    1. Initial program 70.6%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def69.9%

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

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

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

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

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

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

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

    if 3.59999999999999975e-244 < p < 3.7999999999999999e-228 or 7.59999999999999964e-166 < p < 8.50000000000000052e-85

    1. Initial program 64.9%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def64.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)\right)} \]
      2. expm1-log1p64.8%

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

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

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

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

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

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

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

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

    if 1.40000000000000002e-64 < p

    1. Initial program 89.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 3.6 \cdot 10^{-244}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 3.8 \cdot 10^{-228}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 7.6 \cdot 10^{-166}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 8.5 \cdot 10^{-85}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \mathbf{elif}\;p \leq 1.4 \cdot 10^{-64}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 5: 50.6% accurate, 16.5× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 4.3 \cdot 10^{-140}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (if (<= x 4.3e-140) (/ (- p) x) (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if (x <= 4.3e-140) {
		tmp = -p / x;
	} else {
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	}
	return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 4.3d-140) then
        tmp = -p / x
    else
        tmp = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double tmp;
	if (x <= 4.3e-140) {
		tmp = -p / x;
	} else {
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if x <= 4.3e-140:
		tmp = -p / x
	else:
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)))
	return tmp
p = abs(p)
function code(p, x)
	tmp = 0.0
	if (x <= 4.3e-140)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x))));
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (x <= 4.3e-140)
		tmp = -p / x;
	else
		tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := If[LessEqual[x, 4.3e-140], N[((-p) / x), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.3 \cdot 10^{-140}:\\
\;\;\;\;\frac{-p}{x}\\

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


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

    1. Initial program 58.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    8. Simplified27.8%

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

    if 4.29999999999999962e-140 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 4.3 \cdot 10^{-140}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\ \end{array} \]

Alternative 6: 28.2% accurate, 35.5× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{p}{x}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x) :precision binary64 (if (<= x -2e-310) (/ (- p) x) (/ p x)))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = -p / x;
	} else {
		tmp = p / x;
	}
	return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-2d-310)) then
        tmp = -p / x
    else
        tmp = p / x
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double tmp;
	if (x <= -2e-310) {
		tmp = -p / x;
	} else {
		tmp = p / x;
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if x <= -2e-310:
		tmp = -p / x
	else:
		tmp = p / x
	return tmp
p = abs(p)
function code(p, x)
	tmp = 0.0
	if (x <= -2e-310)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = Float64(p / x);
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (x <= -2e-310)
		tmp = -p / x;
	else
		tmp = p / x;
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := If[LessEqual[x, -2e-310], N[((-p) / x), $MachinePrecision], N[(p / x), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-p}{x}\\

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


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

    1. Initial program 57.6%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, 2 \cdot p\right)}{x}}}\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def56.9%

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    8. Simplified28.4%

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

    if -1.999999999999994e-310 < x

    1. Initial program 100.0%

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\left(e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} - 1\right)}\right)} \]
      4. add-exp-log100.0%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\frac{{p}^{2}}{{x}^{2}}}} \]
    5. Taylor expanded in p around 0 3.6%

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

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

Alternative 7: 6.4% accurate, 71.7× speedup?

\[\begin{array}{l} p = |p|\\ \\ \frac{p}{x} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x) :precision binary64 (/ p x))
p = abs(p);
double code(double p, double x) {
	return p / x;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    code = p / x
end function
p = Math.abs(p);
public static double code(double p, double x) {
	return p / x;
}
p = abs(p)
def code(p, x):
	return p / x
p = abs(p)
function code(p, x)
	return Float64(p / x)
end
p = abs(p)
function tmp = code(p, x)
	tmp = p / x;
end
NOTE: p should be positive before calling this function
code[p_, x_] := N[(p / x), $MachinePrecision]
\begin{array}{l}
p = |p|\\
\\
\frac{p}{x}
\end{array}
Derivation
  1. Initial program 75.8%

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

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

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\left(e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} - 1\right)}\right)} \]
    4. add-exp-log75.8%

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

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

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

    \[\leadsto \sqrt{\color{blue}{\frac{{p}^{2}}{{x}^{2}}}} \]
  5. Taylor expanded in p around 0 18.6%

    \[\leadsto \color{blue}{\frac{p}{x}} \]
  6. Final simplification18.6%

    \[\leadsto \frac{p}{x} \]

Developer target: 79.7% 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 2023305 
(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))))))))