Given's Rotation SVD example

Percentage Accurate: 79.7% → 99.6%
Time: 11.5s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 79.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 16.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x))))

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

Alternative 2: 99.4% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 16.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(-p\right) \cdot \frac{\sqrt{2}}{x}\right)} \cdot \sqrt{0.5} \]
    8. Step-by-step derivation
      1. associate-*r/56.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\color{blue}{p \cdot p}} \cdot \sqrt{2}}{-x} \cdot \sqrt{0.5} \]
      12. sqrt-unprod50.2%

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

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

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

    if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x))))

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

Alternative 3: 67.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 2.7 \cdot 10^{-278}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 3.8 \cdot 10^{-153}:\\
\;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{2} \cdot \frac{p\_m}{-x}\right)\\

\mathbf{elif}\;p\_m \leq 2.9 \cdot 10^{+20}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 2.7000000000000001e-278 or 3.80000000000000023e-153 < p < 2.9e20

    1. Initial program 76.3%

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

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

    if 2.7000000000000001e-278 < p < 3.80000000000000023e-153

    1. Initial program 58.1%

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

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

        \[\leadsto \color{blue}{\sqrt{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{0.5}} \]
      3. +-commutative57.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-sqrt57.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-define57.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*57.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-prod57.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-eval57.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-unprod57.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-sqrt57.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.9e20 < p

    1. Initial program 95.5%

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

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

        \[\leadsto \color{blue}{\sqrt{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{0.5}} \]
      3. +-commutative95.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-sqrt95.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-define95.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*95.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-prod95.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-eval95.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-unprod95.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-sqrt95.4%

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

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

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

        \[\leadsto \sqrt{1 + \color{blue}{\frac{0.5 \cdot x}{p}}} \cdot \sqrt{0.5} \]
    7. Simplified89.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 2.7 \cdot 10^{-278}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 3.8 \cdot 10^{-153}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{2} \cdot \frac{p}{-x}\right)\\ \mathbf{elif}\;p \leq 2.9 \cdot 10^{+20}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5} \cdot \sqrt{1 + \frac{x \cdot 0.5}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 67.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 8.8 \cdot 10^{-277}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 9 \cdot 10^{-152}:\\
\;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{2} \cdot \frac{p\_m}{-x}\right)\\

\mathbf{elif}\;p\_m \leq 3.6 \cdot 10^{+22}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 8.79999999999999983e-277 or 9.0000000000000008e-152 < p < 3.6e22

    1. Initial program 76.3%

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

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

    if 8.79999999999999983e-277 < p < 9.0000000000000008e-152

    1. Initial program 58.1%

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

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

        \[\leadsto \color{blue}{\sqrt{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{0.5}} \]
      3. +-commutative57.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-sqrt57.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-define57.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*57.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-prod57.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-eval57.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-unprod57.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-sqrt57.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6e22 < p

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + \color{blue}{\frac{0.25 \cdot x}{p}}} \]
      2. *-commutative89.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 8.8 \cdot 10^{-277}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 9 \cdot 10^{-152}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\sqrt{2} \cdot \frac{p}{-x}\right)\\ \mathbf{elif}\;p \leq 3.6 \cdot 10^{+22}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 67.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 2.2 \cdot 10^{-276}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 1.25 \cdot 10^{-151}:\\
\;\;\;\;\left(-p\_m\right) \cdot \left(\sqrt{0.5} \cdot \frac{\sqrt{2}}{x}\right)\\

\mathbf{elif}\;p\_m \leq 2.2 \cdot 10^{+20}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 2.19999999999999981e-276 or 1.25000000000000001e-151 < p < 2.2e20

    1. Initial program 76.3%

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

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

    if 2.19999999999999981e-276 < p < 1.25000000000000001e-151

    1. Initial program 58.1%

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

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

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

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

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

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

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

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

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

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

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

    if 2.2e20 < p

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + \color{blue}{\frac{0.25 \cdot x}{p}}} \]
      2. *-commutative89.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 2.2 \cdot 10^{-276}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.25 \cdot 10^{-151}:\\ \;\;\;\;\left(-p\right) \cdot \left(\sqrt{0.5} \cdot \frac{\sqrt{2}}{x}\right)\\ \mathbf{elif}\;p \leq 2.2 \cdot 10^{+20}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 67.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.4 \cdot 10^{-277}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 1.65 \cdot 10^{-153}:\\
\;\;\;\;\frac{p\_m \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{-x}\\

\mathbf{elif}\;p\_m \leq 1.02 \cdot 10^{+21}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 1.39999999999999988e-277 or 1.64999999999999994e-153 < p < 1.02e21

    1. Initial program 76.3%

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

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

    if 1.39999999999999988e-277 < p < 1.64999999999999994e-153

    1. Initial program 58.1%

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

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

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

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

    if 1.02e21 < p

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + \color{blue}{\frac{0.25 \cdot x}{p}}} \]
      2. *-commutative89.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.4 \cdot 10^{-277}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 1.65 \cdot 10^{-153}:\\ \;\;\;\;\frac{p \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)}{-x}\\ \mathbf{elif}\;p \leq 1.02 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 3.2 \cdot 10^{+21}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if p < 3.2e21

    1. Initial program 73.8%

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

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

    if 3.2e21 < p

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{0.5 + \color{blue}{\frac{0.25 \cdot x}{p}}} \]
      2. *-commutative89.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 3.2 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 68.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.08 \cdot 10^{+21}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if p < 1.08e21

    1. Initial program 73.8%

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

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

    if 1.08e21 < p

    1. Initial program 95.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.08 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 55.2% accurate, 2.1× speedup?

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

\\
\sqrt{0.5}
\end{array}
Derivation
  1. Initial program 79.3%

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

    \[\leadsto \color{blue}{\sqrt{0.5}} \]
  4. Add Preprocessing

Alternative 10: 17.3% accurate, 35.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+43}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;1.5\\


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

    1. Initial program 46.2%

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-1 \cdot x}}\right)} \]
    4. Step-by-step derivation
      1. neg-mul-123.2%

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-x}}\right)} \]
    6. Taylor expanded in x around 0 23.2%

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

    if -9.5000000000000004e43 < x

    1. Initial program 85.1%

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

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
    4. Applied egg-rr17.1%

      \[\leadsto \color{blue}{1.5} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 14.3% accurate, 35.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+44}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;0.015625\\


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

    1. Initial program 46.2%

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-1 \cdot x}}\right)} \]
    4. Step-by-step derivation
      1. neg-mul-123.2%

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-x}}\right)} \]
    6. Taylor expanded in x around 0 23.2%

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

    if -2.19999999999999996e44 < x

    1. Initial program 85.1%

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

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
    4. Applied egg-rr13.4%

      \[\leadsto \color{blue}{0.015625} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 6.0% accurate, 215.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 79.3%

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-1 \cdot x}}\right)} \]
  4. Step-by-step derivation
    1. neg-mul-16.3%

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{-x}}\right)} \]
  6. Taylor expanded in x around 0 6.3%

    \[\leadsto \color{blue}{0} \]
  7. Add Preprocessing

Developer Target 1: 79.7% accurate, 0.7× speedup?

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

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

Reproduce

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

  :alt
  (! :herbie-platform default (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x))))))

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