Given's Rotation SVD example

Percentage Accurate: 79.3% → 99.7%
Time: 10.6s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 79.3% 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.2× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x, p \cdot 2\right)\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{{\left(\sqrt[3]{t_0}\right)}^{2}}, \sqrt[3]{\frac{x}{t_0}}, 1\right)}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (hypot x (* p 2.0))))
   (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
     (/ (- p) x)
     (sqrt
      (*
       0.5
       (fma
        (/ (pow (cbrt x) 2.0) (pow (cbrt t_0) 2.0))
        (cbrt (/ x t_0))
        1.0))))))
p = abs(p);
double code(double p, double x) {
	double t_0 = hypot(x, (p * 2.0));
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = -p / x;
	} else {
		tmp = sqrt((0.5 * fma((pow(cbrt(x), 2.0) / pow(cbrt(t_0), 2.0)), cbrt((x / t_0)), 1.0)));
	}
	return tmp;
}
p = abs(p)
function code(p, x)
	t_0 = hypot(x, Float64(p * 2.0))
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(Float64(0.5 * fma(Float64((cbrt(x) ^ 2.0) / (cbrt(t_0) ^ 2.0)), cbrt(Float64(x / t_0)), 1.0)));
	end
	return tmp
end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Power[t$95$0, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[(x / t$95$0), $MachinePrecision], 1/3], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p \cdot 2\right)\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\frac{-p}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{{\left(\sqrt[3]{t_0}\right)}^{2}}, \sqrt[3]{\frac{x}{t_0}}, 1\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)))) < -1

    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. Taylor expanded in x around -inf 52.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.7%

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

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

    if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x 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. 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-cbrt-cube80.9%

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\mathsf{fma}\left(\frac{\sqrt[3]{x \cdot x}}{\sqrt[3]{\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)}} \]
    3. Applied egg-rr99.8%

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

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

Alternative 2: 99.7% accurate, 0.4× 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 -1:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;e^{0.5 \cdot \log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\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)))) -1.0)
   (/ (- p) x)
   (exp (* 0.5 (log (fma (/ x (hypot x (* p 2.0))) 0.5 0.5))))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = -p / x;
	} else {
		tmp = exp((0.5 * log(fma((x / hypot(x, (p * 2.0))), 0.5, 0.5))));
	}
	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)))) <= -1.0)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = exp(Float64(0.5 * log(fma(Float64(x / hypot(x, Float64(p * 2.0))), 0.5, 0.5))));
	end
	return 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], -1.0], N[((-p) / x), $MachinePrecision], N[Exp[N[(0.5 * N[Log[N[(N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5 + 0.5), $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 -1:\\
\;\;\;\;\frac{-p}{x}\\

\mathbf{else}:\\
\;\;\;\;e^{0.5 \cdot \log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\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)))) < -1

    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. Taylor expanded in x around -inf 52.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.7%

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

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

    if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x 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. Step-by-step derivation
      1. pow1/299.7%

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

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

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

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

Alternative 3: 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 -1:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\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)))) -1.0)
   (/ (- p) x)
   (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = -p / x;
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
	}
	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)))) <= -1.0) {
		tmp = -p / x;
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0:
		tmp = -p / x
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x)))))
	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)))) <= -1.0)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x)))));
	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)))) <= -1.0)
		tmp = -p / x;
	else
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
	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], -1.0], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p * 2.0), $MachinePrecision] ^ 2 + x ^ 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 -1:\\
\;\;\;\;\frac{-p}{x}\\

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

    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. Taylor expanded in x around -inf 52.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.7%

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

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

    if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x 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. Step-by-step derivation
      1. add-sqr-sqrt99.7%

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

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

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

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

        \[\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-unprod52.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-sqrt99.7%

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

      \[\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.2%

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

Alternative 4: 67.1% accurate, 1.8× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} \mathbf{if}\;p \leq 3.2 \cdot 10^{-267}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.8 \cdot 10^{-81}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 0.00146:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 29000000000000:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (if (<= p 3.2e-267)
   1.0
   (if (<= p 1.8e-81)
     (/ (- p) x)
     (if (<= p 0.00146)
       (sqrt 0.5)
       (if (<= p 29000000000000.0)
         (sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x)))))
         (sqrt (* 0.5 (+ 1.0 (/ x (* p 2.0))))))))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if (p <= 3.2e-267) {
		tmp = 1.0;
	} else if (p <= 1.8e-81) {
		tmp = -p / x;
	} else if (p <= 0.00146) {
		tmp = sqrt(0.5);
	} else if (p <= 29000000000000.0) {
		tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	}
	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 (p <= 3.2d-267) then
        tmp = 1.0d0
    else if (p <= 1.8d-81) then
        tmp = -p / x
    else if (p <= 0.00146d0) then
        tmp = sqrt(0.5d0)
    else if (p <= 29000000000000.0d0) then
        tmp = sqrt((0.5d0 * (2.0d0 * ((p / x) * (p / x)))))
    else
        tmp = sqrt((0.5d0 * (1.0d0 + (x / (p * 2.0d0)))))
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double tmp;
	if (p <= 3.2e-267) {
		tmp = 1.0;
	} else if (p <= 1.8e-81) {
		tmp = -p / x;
	} else if (p <= 0.00146) {
		tmp = Math.sqrt(0.5);
	} else if (p <= 29000000000000.0) {
		tmp = Math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if p <= 3.2e-267:
		tmp = 1.0
	elif p <= 1.8e-81:
		tmp = -p / x
	elif p <= 0.00146:
		tmp = math.sqrt(0.5)
	elif p <= 29000000000000.0:
		tmp = math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))))
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))))
	return tmp
p = abs(p)
function code(p, x)
	tmp = 0.0
	if (p <= 3.2e-267)
		tmp = 1.0;
	elseif (p <= 1.8e-81)
		tmp = Float64(Float64(-p) / x);
	elseif (p <= 0.00146)
		tmp = sqrt(0.5);
	elseif (p <= 29000000000000.0)
		tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x)))));
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(p * 2.0)))));
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (p <= 3.2e-267)
		tmp = 1.0;
	elseif (p <= 1.8e-81)
		tmp = -p / x;
	elseif (p <= 0.00146)
		tmp = sqrt(0.5);
	elseif (p <= 29000000000000.0)
		tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
	else
		tmp = sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := If[LessEqual[p, 3.2e-267], 1.0, If[LessEqual[p, 1.8e-81], N[((-p) / x), $MachinePrecision], If[LessEqual[p, 0.00146], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 29000000000000.0], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(p * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 3.2 \cdot 10^{-267}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 1.8 \cdot 10^{-81}:\\
\;\;\;\;\frac{-p}{x}\\

\mathbf{elif}\;p \leq 0.00146:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;p \leq 29000000000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if p < 3.19999999999999986e-267

    1. Initial program 77.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. add-sqr-sqrt77.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-def77.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*77.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-prod77.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-eval77.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-unprod6.2%

        \[\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-sqrt77.9%

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

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

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

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

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

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

        \[\leadsto {\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{1} \cdot \color{blue}{{\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up77.8%

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
      7. distribute-lft-in77.8%

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

        \[\leadsto {\left({\left(\color{blue}{0.5} + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      9. metadata-eval77.8%

        \[\leadsto {\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr77.8%

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

      \[\leadsto \color{blue}{1} \]

    if 3.19999999999999986e-267 < p < 1.7999999999999999e-81

    1. Initial program 48.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 -inf 22.7%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{x \cdot x}}} \]
      3. unpow222.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.8%

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

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

    if 1.7999999999999999e-81 < p < 0.0014599999999999999

    1. Initial program 84.1%

      \[\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 50.8%

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

    if 0.0014599999999999999 < p < 2.9e13

    1. Initial program 52.0%

      \[\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 53.3%

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

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

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

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

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

    if 2.9e13 < p

    1. Initial program 95.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 3.2 \cdot 10^{-267}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.8 \cdot 10^{-81}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 0.00146:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 29000000000000:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\ \end{array} \]

Alternative 5: 67.0% accurate, 1.8× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} t_0 := \frac{-p}{x}\\ \mathbf{if}\;p \leq 7 \cdot 10^{-268}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.05 \cdot 10^{-80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 0.000205:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 1.3 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\ \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 7e-268)
     1.0
     (if (<= p 1.05e-80)
       t_0
       (if (<= p 0.000205)
         (sqrt 0.5)
         (if (<= p 1.3e+14) t_0 (sqrt (* 0.5 (+ 1.0 (/ x (* p 2.0)))))))))))
p = abs(p);
double code(double p, double x) {
	double t_0 = -p / x;
	double tmp;
	if (p <= 7e-268) {
		tmp = 1.0;
	} else if (p <= 1.05e-80) {
		tmp = t_0;
	} else if (p <= 0.000205) {
		tmp = sqrt(0.5);
	} else if (p <= 1.3e+14) {
		tmp = t_0;
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	}
	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 <= 7d-268) then
        tmp = 1.0d0
    else if (p <= 1.05d-80) then
        tmp = t_0
    else if (p <= 0.000205d0) then
        tmp = sqrt(0.5d0)
    else if (p <= 1.3d+14) then
        tmp = t_0
    else
        tmp = sqrt((0.5d0 * (1.0d0 + (x / (p * 2.0d0)))))
    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 <= 7e-268) {
		tmp = 1.0;
	} else if (p <= 1.05e-80) {
		tmp = t_0;
	} else if (p <= 0.000205) {
		tmp = Math.sqrt(0.5);
	} else if (p <= 1.3e+14) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	t_0 = -p / x
	tmp = 0
	if p <= 7e-268:
		tmp = 1.0
	elif p <= 1.05e-80:
		tmp = t_0
	elif p <= 0.000205:
		tmp = math.sqrt(0.5)
	elif p <= 1.3e+14:
		tmp = t_0
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))))
	return tmp
p = abs(p)
function code(p, x)
	t_0 = Float64(Float64(-p) / x)
	tmp = 0.0
	if (p <= 7e-268)
		tmp = 1.0;
	elseif (p <= 1.05e-80)
		tmp = t_0;
	elseif (p <= 0.000205)
		tmp = sqrt(0.5);
	elseif (p <= 1.3e+14)
		tmp = t_0;
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(p * 2.0)))));
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	t_0 = -p / x;
	tmp = 0.0;
	if (p <= 7e-268)
		tmp = 1.0;
	elseif (p <= 1.05e-80)
		tmp = t_0;
	elseif (p <= 0.000205)
		tmp = sqrt(0.5);
	elseif (p <= 1.3e+14)
		tmp = t_0;
	else
		tmp = sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
	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, 7e-268], 1.0, If[LessEqual[p, 1.05e-80], t$95$0, If[LessEqual[p, 0.000205], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 1.3e+14], t$95$0, N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(p * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 7 \cdot 10^{-268}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 1.05 \cdot 10^{-80}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 0.000205:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;p \leq 1.3 \cdot 10^{+14}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 77.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. add-sqr-sqrt77.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-def77.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*77.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-prod77.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-eval77.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-unprod6.2%

        \[\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-sqrt77.9%

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

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

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

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

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

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

        \[\leadsto {\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{1} \cdot \color{blue}{{\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up77.8%

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
      7. distribute-lft-in77.8%

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

        \[\leadsto {\left({\left(\color{blue}{0.5} + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      9. metadata-eval77.8%

        \[\leadsto {\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr77.8%

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

      \[\leadsto \color{blue}{1} \]

    if 7.00000000000000011e-268 < p < 1.05000000000000001e-80 or 2.05e-4 < p < 1.3e14

    1. Initial program 49.1%

      \[\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 25.7%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{x \cdot x}}} \]
      3. unpow225.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.1%

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

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

    if 1.05000000000000001e-80 < p < 2.05e-4

    1. Initial program 84.1%

      \[\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 50.8%

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

    if 1.3e14 < p

    1. Initial program 95.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 7 \cdot 10^{-268}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.05 \cdot 10^{-80}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 0.000205:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 1.3 \cdot 10^{+14}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\ \end{array} \]

Alternative 6: 67.1% accurate, 2.0× speedup?

\[\begin{array}{l} p = |p|\\ \\ \begin{array}{l} \mathbf{if}\;p \leq 2.6 \cdot 10^{-269}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 6.5 \cdot 10^{-82} \lor \neg \left(p \leq 0.00083\right) \land p \leq 29000000000000:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x)
 :precision binary64
 (if (<= p 2.6e-269)
   1.0
   (if (or (<= p 6.5e-82) (and (not (<= p 0.00083)) (<= p 29000000000000.0)))
     (/ (- p) x)
     (sqrt 0.5))))
p = abs(p);
double code(double p, double x) {
	double tmp;
	if (p <= 2.6e-269) {
		tmp = 1.0;
	} else if ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0))) {
		tmp = -p / x;
	} 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) :: tmp
    if (p <= 2.6d-269) then
        tmp = 1.0d0
    else if ((p <= 6.5d-82) .or. (.not. (p <= 0.00083d0)) .and. (p <= 29000000000000.0d0)) then
        tmp = -p / x
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
	double tmp;
	if (p <= 2.6e-269) {
		tmp = 1.0;
	} else if ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0))) {
		tmp = -p / x;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p = abs(p)
def code(p, x):
	tmp = 0
	if p <= 2.6e-269:
		tmp = 1.0
	elif (p <= 6.5e-82) or (not (p <= 0.00083) and (p <= 29000000000000.0)):
		tmp = -p / x
	else:
		tmp = math.sqrt(0.5)
	return tmp
p = abs(p)
function code(p, x)
	tmp = 0.0
	if (p <= 2.6e-269)
		tmp = 1.0;
	elseif ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0)))
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p = abs(p)
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (p <= 2.6e-269)
		tmp = 1.0;
	elseif ((p <= 6.5e-82) || (~((p <= 0.00083)) && (p <= 29000000000000.0)))
		tmp = -p / x;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
NOTE: p should be positive before calling this function
code[p_, x_] := If[LessEqual[p, 2.6e-269], 1.0, If[Or[LessEqual[p, 6.5e-82], And[N[Not[LessEqual[p, 0.00083]], $MachinePrecision], LessEqual[p, 29000000000000.0]]], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 2.6 \cdot 10^{-269}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 6.5 \cdot 10^{-82} \lor \neg \left(p \leq 0.00083\right) \land p \leq 29000000000000:\\
\;\;\;\;\frac{-p}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 2.6e-269

    1. Initial program 77.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. add-sqr-sqrt77.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-def77.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*77.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-prod77.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-eval77.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-unprod6.2%

        \[\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-sqrt77.9%

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

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

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

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

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

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

        \[\leadsto {\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{1} \cdot \color{blue}{{\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up77.8%

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
      7. distribute-lft-in77.8%

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

        \[\leadsto {\left({\left(\color{blue}{0.5} + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      9. metadata-eval77.8%

        \[\leadsto {\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr77.8%

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

      \[\leadsto \color{blue}{1} \]

    if 2.6e-269 < p < 6.4999999999999997e-82 or 8.3000000000000001e-4 < p < 2.9e13

    1. Initial program 49.1%

      \[\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 25.7%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{x \cdot x}}} \]
      3. unpow225.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg57.1%

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

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

    if 6.4999999999999997e-82 < p < 8.3000000000000001e-4 or 2.9e13 < p

    1. Initial program 93.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 2.6 \cdot 10^{-269}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 6.5 \cdot 10^{-82} \lor \neg \left(p \leq 0.00083\right) \land p \leq 29000000000000:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 7: 55.8% accurate, 35.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 58.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 -inf 28.7%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{x \cdot x}}} \]
      3. unpow228.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot p}{x}} \]
      2. mul-1-neg30.0%

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

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

    if -1.6499999999999999e-127 < x

    1. Initial program 99.2%

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

        \[\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.2%

        \[\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.2%

        \[\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.2%

        \[\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.2%

        \[\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-unprod49.2%

        \[\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-sqrt99.2%

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

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

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

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

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

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

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

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
      7. distribute-lft-in99.2%

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

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

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

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

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

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

Alternative 8: 37.6% accurate, 42.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 49.5%

      \[\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 55.9%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{x \cdot x}}} \]
      3. unpow255.9%

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

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot \left(p \cdot p\right)}{x \cdot x}}} \]
    5. Taylor expanded in p around 0 44.8%

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

    if -3.5999999999999998e85 < x

    1. Initial program 81.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. add-sqr-sqrt81.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-def81.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*81.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-prod81.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-eval81.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-unprod42.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-sqrt81.9%

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

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

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

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

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

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

        \[\leadsto {\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{1} \cdot \color{blue}{{\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up81.9%

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
      7. distribute-lft-in81.9%

        \[\leadsto {\left({\color{blue}{\left(0.5 \cdot 1 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      8. metadata-eval81.9%

        \[\leadsto {\left({\left(\color{blue}{0.5} + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      9. metadata-eval81.9%

        \[\leadsto {\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    5. Applied egg-rr81.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{+85}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 36.2% accurate, 215.0× speedup?

\[\begin{array}{l} p = |p|\\ \\ 1 \end{array} \]
NOTE: p should be positive before calling this function
(FPCore (p x) :precision binary64 1.0)
p = abs(p);
double code(double p, double x) {
	return 1.0;
}
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 = 1.0d0
end function
p = Math.abs(p);
public static double code(double p, double x) {
	return 1.0;
}
p = abs(p)
def code(p, x):
	return 1.0
p = abs(p)
function code(p, x)
	return 1.0
end
p = abs(p)
function tmp = code(p, x)
	tmp = 1.0;
end
NOTE: p should be positive before calling this function
code[p_, x_] := 1.0
\begin{array}{l}
p = |p|\\
\\
1
\end{array}
Derivation
  1. Initial program 78.3%

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

      \[\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-def78.3%

      \[\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*78.3%

      \[\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-prod78.3%

      \[\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-eval78.3%

      \[\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-unprod40.9%

      \[\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-sqrt78.3%

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

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

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

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

      \[\leadsto {\left(\color{blue}{\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)} \cdot \sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}\right)}^{0.3333333333333333} \]
    4. pow178.3%

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

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

      \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)\right)}^{\left(1 + 0.5\right)}\right)}}^{0.3333333333333333} \]
    7. distribute-lft-in78.3%

      \[\leadsto {\left({\color{blue}{\left(0.5 \cdot 1 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
    8. metadata-eval78.3%

      \[\leadsto {\left({\left(\color{blue}{0.5} + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
    9. metadata-eval78.3%

      \[\leadsto {\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
  5. Applied egg-rr78.3%

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

    \[\leadsto \color{blue}{1} \]
  7. Final simplification33.9%

    \[\leadsto 1 \]

Developer target: 79.3% 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 2023229 
(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))))))))