Given's Rotation SVD example

Percentage Accurate: 79.6% → 99.8%
Time: 9.6s
Alternatives: 9
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 9 alternatives:

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

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

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

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

    1. Initial program 18.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    10. Simplified59.0%

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 18.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    10. Simplified59.0%

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 82.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.96:\\
\;\;\;\;\frac{-p_m}{x}\\

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


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

    1. Initial program 48.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. add-log-exp48.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. +-commutative48.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-sqrt48.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-def48.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    10. Simplified42.3%

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

    if -1.96 < x

    1. Initial program 87.8%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt87.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-def87.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*87.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-prod87.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-eval87.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-unprod43.0%

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot \color{blue}{p}, x\right)}\right)} \]
    4. Applied egg-rr87.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 simplification76.4%

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

Alternative 4: 64.8% accurate, 1.8× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} t_0 := \frac{-p_m}{x}\\ \mathbf{if}\;x \leq -2.65:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-63}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p_m}}\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-28}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (let* ((t_0 (/ (- p_m) x)))
   (if (<= x -2.65)
     t_0
     (if (<= x -3.5e-63)
       (sqrt (+ 0.5 (/ (* x 0.25) p_m)))
       (if (<= x -2.3e-70) t_0 (if (<= x 1e-28) (sqrt 0.5) 1.0))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double t_0 = -p_m / x;
	double tmp;
	if (x <= -2.65) {
		tmp = t_0;
	} else if (x <= -3.5e-63) {
		tmp = sqrt((0.5 + ((x * 0.25) / p_m)));
	} else if (x <= -2.3e-70) {
		tmp = t_0;
	} else if (x <= 1e-28) {
		tmp = sqrt(0.5);
	} else {
		tmp = 1.0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = -p_m / x
    if (x <= (-2.65d0)) then
        tmp = t_0
    else if (x <= (-3.5d-63)) then
        tmp = sqrt((0.5d0 + ((x * 0.25d0) / p_m)))
    else if (x <= (-2.3d-70)) then
        tmp = t_0
    else if (x <= 1d-28) then
        tmp = sqrt(0.5d0)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double t_0 = -p_m / x;
	double tmp;
	if (x <= -2.65) {
		tmp = t_0;
	} else if (x <= -3.5e-63) {
		tmp = Math.sqrt((0.5 + ((x * 0.25) / p_m)));
	} else if (x <= -2.3e-70) {
		tmp = t_0;
	} else if (x <= 1e-28) {
		tmp = Math.sqrt(0.5);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	t_0 = -p_m / x
	tmp = 0
	if x <= -2.65:
		tmp = t_0
	elif x <= -3.5e-63:
		tmp = math.sqrt((0.5 + ((x * 0.25) / p_m)))
	elif x <= -2.3e-70:
		tmp = t_0
	elif x <= 1e-28:
		tmp = math.sqrt(0.5)
	else:
		tmp = 1.0
	return tmp
p_m = abs(p)
function code(p_m, x)
	t_0 = Float64(Float64(-p_m) / x)
	tmp = 0.0
	if (x <= -2.65)
		tmp = t_0;
	elseif (x <= -3.5e-63)
		tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.25) / p_m)));
	elseif (x <= -2.3e-70)
		tmp = t_0;
	elseif (x <= 1e-28)
		tmp = sqrt(0.5);
	else
		tmp = 1.0;
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	t_0 = -p_m / x;
	tmp = 0.0;
	if (x <= -2.65)
		tmp = t_0;
	elseif (x <= -3.5e-63)
		tmp = sqrt((0.5 + ((x * 0.25) / p_m)));
	elseif (x <= -2.3e-70)
		tmp = t_0;
	elseif (x <= 1e-28)
		tmp = sqrt(0.5);
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, If[LessEqual[x, -2.65], t$95$0, If[LessEqual[x, -3.5e-63], N[Sqrt[N[(0.5 + N[(N[(x * 0.25), $MachinePrecision] / p$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, -2.3e-70], t$95$0, If[LessEqual[x, 1e-28], N[Sqrt[0.5], $MachinePrecision], 1.0]]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
t_0 := \frac{-p_m}{x}\\
\mathbf{if}\;x \leq -2.65:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -3.5 \cdot 10^{-63}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p_m}}\\

\mathbf{elif}\;x \leq -2.3 \cdot 10^{-70}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 10^{-28}:\\
\;\;\;\;\sqrt{0.5}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -2.64999999999999991 or -3.50000000000000003e-63 < x < -2.30000000000000001e-70

    1. Initial program 45.8%

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

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

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

        \[\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-def45.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*45.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-prod45.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-eval45.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-unprod23.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-sqrt45.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.64999999999999991 < x < -3.50000000000000003e-63

    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. Step-by-step derivation
      1. add-log-exp73.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.30000000000000001e-70 < x < 9.99999999999999971e-29

    1. Initial program 87.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 0 70.1%

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

    if 9.99999999999999971e-29 < 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-log-exp100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.65:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;x \leq -3.5 \cdot 10^{-63}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-70}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;x \leq 10^{-28}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 65.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05:\\
\;\;\;\;\frac{-p_m}{x}\\

\mathbf{elif}\;x \leq 3.7 \cdot 10^{-28}:\\
\;\;\;\;\sqrt{0.5}\\

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


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

    1. Initial program 48.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. add-log-exp48.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. +-commutative48.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-sqrt48.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-def48.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    10. Simplified42.3%

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

    if -1.05000000000000004 < x < 3.7000000000000002e-28

    1. Initial program 80.7%

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

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

    if 3.7000000000000002e-28 < 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-log-exp100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification63.7%

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

Alternative 6: 55.3% accurate, 23.8× speedup?

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

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

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


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

    1. Initial program 58.6%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-log-exp58.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. +-commutative58.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-sqrt58.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-def58.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*58.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-prod58.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-eval58.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-unprod32.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    10. Simplified31.6%

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

    if -4.7999999999999998e-143 < 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-log-exp100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 37.1% accurate, 24.5× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+24}:\\ \;\;\;\;\mathsf{reciprocal}\left(\left(\frac{x}{p_m}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= x -9.5e+24) (reciprocal (/ x p_m)) 1.0))
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{reciprocal}\left(\left(\frac{x}{p_m}\right)\right)\\

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


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

    1. Initial program 50.9%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{{x}^{2}}}} \]
    5. Simplified44.0%

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

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

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

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

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

        \[\leadsto \frac{\sqrt{\color{blue}{{p}^{2}}}}{\sqrt{{x}^{2}}} \]
      6. unpow260.1%

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

        \[\leadsto \frac{\color{blue}{\sqrt{p} \cdot \sqrt{p}}}{\sqrt{{x}^{2}}} \]
      8. add-sqr-sqrt44.2%

        \[\leadsto \frac{\color{blue}{p}}{\sqrt{{x}^{2}}} \]
      9. unpow244.2%

        \[\leadsto \frac{p}{\sqrt{\color{blue}{x \cdot x}}} \]
      10. sqrt-prod0.0%

        \[\leadsto \frac{p}{\color{blue}{\sqrt{x} \cdot \sqrt{x}}} \]
      11. add-sqr-sqrt45.4%

        \[\leadsto \frac{p}{\color{blue}{x}} \]
      12. clear-num45.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{p}}} \]
      13. reciprocal-define29.4%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(\frac{x}{p}\right)\right)} \]
    7. Applied egg-rr29.4%

      \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(\frac{x}{p}\right)\right)} \]

    if -9.5000000000000001e24 < x

    1. Initial program 85.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-log-exp85.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+24}:\\ \;\;\;\;\mathsf{reciprocal}\left(\left(\frac{x}{p}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 37.1% accurate, 26.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{p_m}{x}\\

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


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

    1. Initial program 50.9%

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

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

        \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{{x}^{2}}}} \]
    5. Simplified44.0%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{2 \cdot {p}^{2}}{{x}^{2}}}} \]
    6. Taylor expanded in p around 0 45.4%

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

    if -9.1999999999999992e25 < x

    1. Initial program 85.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-log-exp85.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 36.2% accurate, 215.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 77.8%

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

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

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

      \[\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.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*77.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-prod77.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-eval77.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-unprod38.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  9. Final simplification36.5%

    \[\leadsto 1 \]
  10. Add Preprocessing

Developer target: 79.6% 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 2024024 
(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))))))))