Given's Rotation SVD example

Percentage Accurate: 78.9% → 99.8%
Time: 10.0s
Alternatives: 7
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 78.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\right)}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
   (fabs (/ p x))
   (sqrt (* 0.5 (log (exp (+ 1.0 (/ x (hypot x (* p 2.0))))))))))
double code(double p, double x) {
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = fabs((p / x));
	} else {
		tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p * 2.0))))))));
	}
	return tmp;
}
public static double code(double p, double x) {
	double tmp;
	if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = Math.abs((p / x));
	} else {
		tmp = Math.sqrt((0.5 * Math.log(Math.exp((1.0 + (x / Math.hypot(x, (p * 2.0))))))));
	}
	return tmp;
}
def code(p, x):
	tmp = 0
	if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0:
		tmp = math.fabs((p / x))
	else:
		tmp = math.sqrt((0.5 * math.log(math.exp((1.0 + (x / math.hypot(x, (p * 2.0))))))))
	return tmp
function code(p, x)
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = abs(Float64(p / x));
	else
		tmp = sqrt(Float64(0.5 * log(exp(Float64(1.0 + Float64(x / hypot(x, Float64(p * 2.0))))))));
	end
	return tmp
end
function tmp_2 = code(p, x)
	tmp = 0.0;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0)
		tmp = abs((p / x));
	else
		tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p * 2.0))))))));
	end
	tmp_2 = tmp;
end
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[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[Log[N[Exp[N[(1.0 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\left|\frac{p}{x}\right|\\

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5} \cdot \sqrt{\color{blue}{2 \cdot \frac{{p}^{2}}{{x}^{2}}}} \]
      13. pow1/258.5%

        \[\leadsto \color{blue}{{0.5}^{0.5}} \cdot \sqrt{2 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
      14. pow1/258.5%

        \[\leadsto {0.5}^{0.5} \cdot \color{blue}{{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}^{0.5}} \]
      15. pow-prod-down58.7%

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{p}{x}\right)}^{2}}} \]
      5. unpow266.7%

        \[\leadsto \sqrt{\color{blue}{\frac{p}{x} \cdot \frac{p}{x}}} \]
      6. rem-sqrt-square100.0%

        \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
    10. Simplified100.0%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]

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

    1. Initial program 99.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-log-exp99.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right) + -0.5}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
   (fabs (/ p x))
   (sqrt (+ (* 0.5 (+ 2.0 (/ x (hypot x (* p 2.0))))) -0.5))))
double code(double p, double x) {
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = fabs((p / x));
	} else {
		tmp = sqrt(((0.5 * (2.0 + (x / hypot(x, (p * 2.0))))) + -0.5));
	}
	return tmp;
}
public static double code(double p, double x) {
	double tmp;
	if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = Math.abs((p / x));
	} else {
		tmp = Math.sqrt(((0.5 * (2.0 + (x / Math.hypot(x, (p * 2.0))))) + -0.5));
	}
	return tmp;
}
def code(p, x):
	tmp = 0
	if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0:
		tmp = math.fabs((p / x))
	else:
		tmp = math.sqrt(((0.5 * (2.0 + (x / math.hypot(x, (p * 2.0))))) + -0.5))
	return tmp
function code(p, x)
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = abs(Float64(p / x));
	else
		tmp = sqrt(Float64(Float64(0.5 * Float64(2.0 + Float64(x / hypot(x, Float64(p * 2.0))))) + -0.5));
	end
	return tmp
end
function tmp_2 = code(p, x)
	tmp = 0.0;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0)
		tmp = abs((p / x));
	else
		tmp = sqrt(((0.5 * (2.0 + (x / hypot(x, (p * 2.0))))) + -0.5));
	end
	tmp_2 = tmp;
end
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[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(N[(0.5 * N[(2.0 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\left|\frac{p}{x}\right|\\

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


\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 17.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5} \cdot \sqrt{\color{blue}{2 \cdot \frac{{p}^{2}}{{x}^{2}}}} \]
      13. pow1/258.5%

        \[\leadsto \color{blue}{{0.5}^{0.5}} \cdot \sqrt{2 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
      14. pow1/258.5%

        \[\leadsto {0.5}^{0.5} \cdot \color{blue}{{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}^{0.5}} \]
      15. pow-prod-down58.7%

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{p}{x}\right)}^{2}}} \]
      5. unpow266.7%

        \[\leadsto \sqrt{\color{blue}{\frac{p}{x} \cdot \frac{p}{x}}} \]
      6. rem-sqrt-square100.0%

        \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
    10. Simplified100.0%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]

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

    1. Initial program 99.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. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(1 + \left(1 + \left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} + -1\right)\right)\right) \cdot 0.5}}\right)} - 1 \]
      4. associate-+r+98.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{+104} \lor \neg \left(x \leq -7.2 \cdot 10^{+47}\right) \land x \leq -9.2 \cdot 10^{-29}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (if (or (<= x -2.4e+104) (and (not (<= x -7.2e+47)) (<= x -9.2e-29)))
   (fabs (/ p x))
   (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
double code(double p, double x) {
	double tmp;
	if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29))) {
		tmp = fabs((p / x));
	} else {
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
	}
	return tmp;
}
public static double code(double p, double x) {
	double tmp;
	if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29))) {
		tmp = Math.abs((p / x));
	} else {
		tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
	}
	return tmp;
}
def code(p, x):
	tmp = 0
	if (x <= -2.4e+104) or (not (x <= -7.2e+47) and (x <= -9.2e-29)):
		tmp = math.fabs((p / x))
	else:
		tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x)))))
	return tmp
function code(p, x)
	tmp = 0.0
	if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29)))
		tmp = abs(Float64(p / x));
	else
		tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x)))));
	end
	return tmp
end
function tmp_2 = code(p, x)
	tmp = 0.0;
	if ((x <= -2.4e+104) || (~((x <= -7.2e+47)) && (x <= -9.2e-29)))
		tmp = abs((p / x));
	else
		tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
	end
	tmp_2 = tmp;
end
code[p_, x_] := If[Or[LessEqual[x, -2.4e+104], And[N[Not[LessEqual[x, -7.2e+47]], $MachinePrecision], LessEqual[x, -9.2e-29]]], N[Abs[N[(p / x), $MachinePrecision]], $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}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+104} \lor \neg \left(x \leq -7.2 \cdot 10^{+47}\right) \land x \leq -9.2 \cdot 10^{-29}:\\
\;\;\;\;\left|\frac{p}{x}\right|\\

\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 x < -2.4e104 or -7.20000000000000015e47 < x < -9.19999999999999965e-29

    1. Initial program 33.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. *-commutative33.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{2}}}} \cdot \sqrt{0.5} \]
    6. Simplified47.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5} \cdot \color{blue}{\sqrt{\frac{{p}^{2}}{{x}^{2}} \cdot 2}} \]
      12. *-commutative47.4%

        \[\leadsto \sqrt{0.5} \cdot \sqrt{\color{blue}{2 \cdot \frac{{p}^{2}}{{x}^{2}}}} \]
      13. pow1/247.4%

        \[\leadsto \color{blue}{{0.5}^{0.5}} \cdot \sqrt{2 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
      14. pow1/247.4%

        \[\leadsto {0.5}^{0.5} \cdot \color{blue}{{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}^{0.5}} \]
      15. pow-prod-down47.5%

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{1} \cdot {\left(\frac{p}{x}\right)}^{2}} \]
      4. *-lft-identity47.8%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{p}{x}\right)}^{2}}} \]
      5. unpow247.8%

        \[\leadsto \sqrt{\color{blue}{\frac{p}{x} \cdot \frac{p}{x}}} \]
      6. rem-sqrt-square75.2%

        \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
    10. Simplified75.2%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]

    if -2.4e104 < x < -7.20000000000000015e47 or -9.19999999999999965e-29 < x

    1. Initial program 90.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-sqrt90.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-def90.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{+104} \lor \neg \left(x \leq -7.2 \cdot 10^{+47}\right) \land x \leq -9.2 \cdot 10^{-29}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}\\ \end{array} \]

Alternative 4: 48.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{p}{x}\right|\\ \mathbf{if}\;p \leq 5 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 4.9 \cdot 10^{-132}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.46 \cdot 10^{-120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 5 \cdot 10^{-89}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 10^{-37}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x}{p} \cdot 0.25}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (fabs (/ p x))))
   (if (<= p 5e-254)
     t_0
     (if (<= p 4.9e-132)
       1.0
       (if (<= p 1.46e-120)
         t_0
         (if (<= p 5e-89)
           1.0
           (if (<= p 1e-37)
             (sqrt 0.5)
             (if (<= p 3.3e+28) t_0 (sqrt (+ 0.5 (* (/ x p) 0.25)))))))))))
double code(double p, double x) {
	double t_0 = fabs((p / x));
	double tmp;
	if (p <= 5e-254) {
		tmp = t_0;
	} else if (p <= 4.9e-132) {
		tmp = 1.0;
	} else if (p <= 1.46e-120) {
		tmp = t_0;
	} else if (p <= 5e-89) {
		tmp = 1.0;
	} else if (p <= 1e-37) {
		tmp = sqrt(0.5);
	} else if (p <= 3.3e+28) {
		tmp = t_0;
	} else {
		tmp = sqrt((0.5 + ((x / p) * 0.25)));
	}
	return tmp;
}
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 = abs((p / x))
    if (p <= 5d-254) then
        tmp = t_0
    else if (p <= 4.9d-132) then
        tmp = 1.0d0
    else if (p <= 1.46d-120) then
        tmp = t_0
    else if (p <= 5d-89) then
        tmp = 1.0d0
    else if (p <= 1d-37) then
        tmp = sqrt(0.5d0)
    else if (p <= 3.3d+28) then
        tmp = t_0
    else
        tmp = sqrt((0.5d0 + ((x / p) * 0.25d0)))
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double t_0 = Math.abs((p / x));
	double tmp;
	if (p <= 5e-254) {
		tmp = t_0;
	} else if (p <= 4.9e-132) {
		tmp = 1.0;
	} else if (p <= 1.46e-120) {
		tmp = t_0;
	} else if (p <= 5e-89) {
		tmp = 1.0;
	} else if (p <= 1e-37) {
		tmp = Math.sqrt(0.5);
	} else if (p <= 3.3e+28) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt((0.5 + ((x / p) * 0.25)));
	}
	return tmp;
}
def code(p, x):
	t_0 = math.fabs((p / x))
	tmp = 0
	if p <= 5e-254:
		tmp = t_0
	elif p <= 4.9e-132:
		tmp = 1.0
	elif p <= 1.46e-120:
		tmp = t_0
	elif p <= 5e-89:
		tmp = 1.0
	elif p <= 1e-37:
		tmp = math.sqrt(0.5)
	elif p <= 3.3e+28:
		tmp = t_0
	else:
		tmp = math.sqrt((0.5 + ((x / p) * 0.25)))
	return tmp
function code(p, x)
	t_0 = abs(Float64(p / x))
	tmp = 0.0
	if (p <= 5e-254)
		tmp = t_0;
	elseif (p <= 4.9e-132)
		tmp = 1.0;
	elseif (p <= 1.46e-120)
		tmp = t_0;
	elseif (p <= 5e-89)
		tmp = 1.0;
	elseif (p <= 1e-37)
		tmp = sqrt(0.5);
	elseif (p <= 3.3e+28)
		tmp = t_0;
	else
		tmp = sqrt(Float64(0.5 + Float64(Float64(x / p) * 0.25)));
	end
	return tmp
end
function tmp_2 = code(p, x)
	t_0 = abs((p / x));
	tmp = 0.0;
	if (p <= 5e-254)
		tmp = t_0;
	elseif (p <= 4.9e-132)
		tmp = 1.0;
	elseif (p <= 1.46e-120)
		tmp = t_0;
	elseif (p <= 5e-89)
		tmp = 1.0;
	elseif (p <= 1e-37)
		tmp = sqrt(0.5);
	elseif (p <= 3.3e+28)
		tmp = t_0;
	else
		tmp = sqrt((0.5 + ((x / p) * 0.25)));
	end
	tmp_2 = tmp;
end
code[p_, x_] := Block[{t$95$0 = N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[p, 5e-254], t$95$0, If[LessEqual[p, 4.9e-132], 1.0, If[LessEqual[p, 1.46e-120], t$95$0, If[LessEqual[p, 5e-89], 1.0, If[LessEqual[p, 1e-37], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 3.3e+28], t$95$0, N[Sqrt[N[(0.5 + N[(N[(x / p), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{p}{x}\right|\\
\mathbf{if}\;p \leq 5 \cdot 10^{-254}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 4.9 \cdot 10^{-132}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 1.46 \cdot 10^{-120}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 5 \cdot 10^{-89}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 10^{-37}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;p \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 5.0000000000000003e-254 or 4.89999999999999981e-132 < p < 1.4599999999999999e-120 or 1.00000000000000007e-37 < p < 3.3e28

    1. Initial program 73.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. *-commutative73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5} \cdot \color{blue}{\sqrt{\frac{{p}^{2}}{{x}^{2}} \cdot 2}} \]
      12. *-commutative21.9%

        \[\leadsto \sqrt{0.5} \cdot \sqrt{\color{blue}{2 \cdot \frac{{p}^{2}}{{x}^{2}}}} \]
      13. pow1/221.9%

        \[\leadsto \color{blue}{{0.5}^{0.5}} \cdot \sqrt{2 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
      14. pow1/221.9%

        \[\leadsto {0.5}^{0.5} \cdot \color{blue}{{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}^{0.5}} \]
      15. pow-prod-down21.9%

        \[\leadsto \color{blue}{{\left(0.5 \cdot \left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)\right)}^{0.5}} \]
    8. Applied egg-rr25.4%

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{p}{x}\right)}^{2}}} \]
      5. unpow225.4%

        \[\leadsto \sqrt{\color{blue}{\frac{p}{x} \cdot \frac{p}{x}}} \]
      6. rem-sqrt-square36.0%

        \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
    10. Simplified36.0%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]

    if 5.0000000000000003e-254 < p < 4.89999999999999981e-132 or 1.4599999999999999e-120 < p < 4.99999999999999967e-89

    1. Initial program 65.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. add-log-exp65.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{0.5} \cdot \sqrt{\log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}}\right)}} \]
      2. rem-log-exp64.2%

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

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

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

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

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

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

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

        \[\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)}}} \]
      10. pow1/365.1%

        \[\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}} \]
    5. Applied egg-rr65.1%

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

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

    if 4.99999999999999967e-89 < p < 1.00000000000000007e-37

    1. Initial program 72.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 50.4%

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

    if 3.3e28 < p

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{0.5 + 0.25 \cdot \frac{x}{p}}} \]
    5. Step-by-step derivation
      1. *-commutative92.7%

        \[\leadsto \sqrt{0.5 + \color{blue}{\frac{x}{p} \cdot 0.25}} \]
    6. Simplified92.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 5 \cdot 10^{-254}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{elif}\;p \leq 4.9 \cdot 10^{-132}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.46 \cdot 10^{-120}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{elif}\;p \leq 5 \cdot 10^{-89}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 10^{-37}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x}{p} \cdot 0.25}\\ \end{array} \]

Alternative 5: 49.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{p}{x}\right|\\ \mathbf{if}\;p \leq 4.5 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 1.3 \cdot 10^{-131}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 2.6 \cdot 10^{-120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 7 \cdot 10^{-87}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.2 \cdot 10^{-38}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 3.4 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (fabs (/ p x))))
   (if (<= p 4.5e-254)
     t_0
     (if (<= p 1.3e-131)
       1.0
       (if (<= p 2.6e-120)
         t_0
         (if (<= p 7e-87)
           1.0
           (if (<= p 1.2e-38)
             (sqrt 0.5)
             (if (<= p 3.4e-10) t_0 (sqrt 0.5)))))))))
double code(double p, double x) {
	double t_0 = fabs((p / x));
	double tmp;
	if (p <= 4.5e-254) {
		tmp = t_0;
	} else if (p <= 1.3e-131) {
		tmp = 1.0;
	} else if (p <= 2.6e-120) {
		tmp = t_0;
	} else if (p <= 7e-87) {
		tmp = 1.0;
	} else if (p <= 1.2e-38) {
		tmp = sqrt(0.5);
	} else if (p <= 3.4e-10) {
		tmp = t_0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
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 = abs((p / x))
    if (p <= 4.5d-254) then
        tmp = t_0
    else if (p <= 1.3d-131) then
        tmp = 1.0d0
    else if (p <= 2.6d-120) then
        tmp = t_0
    else if (p <= 7d-87) then
        tmp = 1.0d0
    else if (p <= 1.2d-38) then
        tmp = sqrt(0.5d0)
    else if (p <= 3.4d-10) then
        tmp = t_0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double t_0 = Math.abs((p / x));
	double tmp;
	if (p <= 4.5e-254) {
		tmp = t_0;
	} else if (p <= 1.3e-131) {
		tmp = 1.0;
	} else if (p <= 2.6e-120) {
		tmp = t_0;
	} else if (p <= 7e-87) {
		tmp = 1.0;
	} else if (p <= 1.2e-38) {
		tmp = Math.sqrt(0.5);
	} else if (p <= 3.4e-10) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
def code(p, x):
	t_0 = math.fabs((p / x))
	tmp = 0
	if p <= 4.5e-254:
		tmp = t_0
	elif p <= 1.3e-131:
		tmp = 1.0
	elif p <= 2.6e-120:
		tmp = t_0
	elif p <= 7e-87:
		tmp = 1.0
	elif p <= 1.2e-38:
		tmp = math.sqrt(0.5)
	elif p <= 3.4e-10:
		tmp = t_0
	else:
		tmp = math.sqrt(0.5)
	return tmp
function code(p, x)
	t_0 = abs(Float64(p / x))
	tmp = 0.0
	if (p <= 4.5e-254)
		tmp = t_0;
	elseif (p <= 1.3e-131)
		tmp = 1.0;
	elseif (p <= 2.6e-120)
		tmp = t_0;
	elseif (p <= 7e-87)
		tmp = 1.0;
	elseif (p <= 1.2e-38)
		tmp = sqrt(0.5);
	elseif (p <= 3.4e-10)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
function tmp_2 = code(p, x)
	t_0 = abs((p / x));
	tmp = 0.0;
	if (p <= 4.5e-254)
		tmp = t_0;
	elseif (p <= 1.3e-131)
		tmp = 1.0;
	elseif (p <= 2.6e-120)
		tmp = t_0;
	elseif (p <= 7e-87)
		tmp = 1.0;
	elseif (p <= 1.2e-38)
		tmp = sqrt(0.5);
	elseif (p <= 3.4e-10)
		tmp = t_0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
code[p_, x_] := Block[{t$95$0 = N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[p, 4.5e-254], t$95$0, If[LessEqual[p, 1.3e-131], 1.0, If[LessEqual[p, 2.6e-120], t$95$0, If[LessEqual[p, 7e-87], 1.0, If[LessEqual[p, 1.2e-38], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 3.4e-10], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{p}{x}\right|\\
\mathbf{if}\;p \leq 4.5 \cdot 10^{-254}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 1.3 \cdot 10^{-131}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 2.6 \cdot 10^{-120}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;p \leq 7 \cdot 10^{-87}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 1.2 \cdot 10^{-38}:\\
\;\;\;\;\sqrt{0.5}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 4.5e-254 or 1.29999999999999998e-131 < p < 2.6000000000000001e-120 or 1.20000000000000011e-38 < p < 3.40000000000000015e-10

    1. Initial program 75.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. *-commutative75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-p}{\frac{x}{\sqrt{2}}}} \cdot \sqrt{0.5} \]
    7. Step-by-step derivation
      1. *-commutative16.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5} \cdot \sqrt{\color{blue}{2 \cdot \frac{{p}^{2}}{{x}^{2}}}} \]
      13. pow1/219.3%

        \[\leadsto \color{blue}{{0.5}^{0.5}} \cdot \sqrt{2 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
      14. pow1/219.3%

        \[\leadsto {0.5}^{0.5} \cdot \color{blue}{{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}^{0.5}} \]
      15. pow-prod-down19.3%

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{1} \cdot {\left(\frac{p}{x}\right)}^{2}} \]
      4. *-lft-identity23.0%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{p}{x}\right)}^{2}}} \]
      5. unpow223.0%

        \[\leadsto \sqrt{\color{blue}{\frac{p}{x} \cdot \frac{p}{x}}} \]
      6. rem-sqrt-square34.3%

        \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
    10. Simplified34.3%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]

    if 4.5e-254 < p < 1.29999999999999998e-131 or 2.6000000000000001e-120 < p < 7.00000000000000023e-87

    1. Initial program 65.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. add-log-exp65.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{0.5} \cdot \sqrt{\log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}}\right)}} \]
      2. rem-log-exp64.2%

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

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

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

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

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

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

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

        \[\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)}}} \]
      10. pow1/365.1%

        \[\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}} \]
    5. Applied egg-rr65.1%

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

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

    if 7.00000000000000023e-87 < p < 1.20000000000000011e-38 or 3.40000000000000015e-10 < p

    1. Initial program 84.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 0 77.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 4.5 \cdot 10^{-254}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{elif}\;p \leq 1.3 \cdot 10^{-131}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 2.6 \cdot 10^{-120}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{elif}\;p \leq 7 \cdot 10^{-87}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.2 \cdot 10^{-38}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 3.4 \cdot 10^{-10}:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 6: 53.2% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;p \leq 1.25 \cdot 10^{-85}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
(FPCore (p x) :precision binary64 (if (<= p 1.25e-85) 1.0 (sqrt 0.5)))
double code(double p, double x) {
	double tmp;
	if (p <= 1.25e-85) {
		tmp = 1.0;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: tmp
    if (p <= 1.25d-85) then
        tmp = 1.0d0
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double tmp;
	if (p <= 1.25e-85) {
		tmp = 1.0;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
def code(p, x):
	tmp = 0
	if p <= 1.25e-85:
		tmp = 1.0
	else:
		tmp = math.sqrt(0.5)
	return tmp
function code(p, x)
	tmp = 0.0
	if (p <= 1.25e-85)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (p <= 1.25e-85)
		tmp = 1.0;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
code[p_, x_] := If[LessEqual[p, 1.25e-85], 1.0, N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;p \leq 1.25 \cdot 10^{-85}:\\
\;\;\;\;1\\

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


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

    1. Initial program 75.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-log-exp75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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)}}} \]
      10. pow1/375.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}} \]
    5. Applied egg-rr75.9%

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

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

    if 1.25e-85 < p

    1. Initial program 80.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 72.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.25 \cdot 10^{-85}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 7: 35.7% accurate, 215.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 77.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. add-log-exp77.6%

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, \color{blue}{2} \cdot \sqrt{p \cdot p}\right)}}\right)} \]
    8. sqrt-unprod35.7%

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

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

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

      \[\leadsto \color{blue}{\sqrt{0.5} \cdot \sqrt{\log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}}\right)}} \]
    2. rem-log-exp77.3%

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

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

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

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

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

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

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

      \[\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)}}} \]
    10. pow1/377.6%

      \[\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}} \]
  5. Applied egg-rr77.6%

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

    \[\leadsto \color{blue}{1} \]
  7. Final simplification32.5%

    \[\leadsto 1 \]

Developer target: 78.9% 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 2023310 
(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))))))))