Given's Rotation SVD example

Percentage Accurate: 79.4% → 99.9%
Time: 9.8s
Alternatives: 6
Speedup: 1.8×

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 6 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.4% 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.9% accurate, 0.4× speedup?

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

    1. Initial program 16.8%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. add-log-exp16.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. +-commutative16.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-sqrt16.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-def16.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-*r*16.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. *-commutative16.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + -0.25 \cdot \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}}} \]
    7. Step-by-step derivation
      1. +-commutative44.8%

        \[\leadsto \color{blue}{-0.25 \cdot \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. fma-def44.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}}, -1 \cdot \frac{p}{x}\right)} \]
      3. distribute-rgt-out44.8%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{\color{blue}{{p}^{4} \cdot \left(-4 + -2\right)}}{p \cdot {x}^{3}}, -1 \cdot \frac{p}{x}\right) \]
      4. times-frac48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \color{blue}{\frac{{p}^{4}}{p} \cdot \frac{-4 + -2}{{x}^{3}}}, -1 \cdot \frac{p}{x}\right) \]
      5. metadata-eval48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{\color{blue}{-6}}{{x}^{3}}, -1 \cdot \frac{p}{x}\right) \]
      6. associate-*r/48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \color{blue}{\frac{-1 \cdot p}{x}}\right) \]
      7. mul-1-neg48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \frac{\color{blue}{-p}}{x}\right) \]
    8. Simplified48.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \frac{-p}{x}\right)} \]
    9. Taylor expanded in p around 0 51.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + 1.5 \cdot \frac{{p}^{3}}{{x}^{3}}} \]
    10. Step-by-step derivation
      1. +-commutative51.2%

        \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. mul-1-neg51.2%

        \[\leadsto 1.5 \cdot \frac{{p}^{3}}{{x}^{3}} + \color{blue}{\left(-\frac{p}{x}\right)} \]
      3. unsub-neg51.2%

        \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}} - \frac{p}{x}} \]
      4. *-commutative51.2%

        \[\leadsto \color{blue}{\frac{{p}^{3}}{{x}^{3}} \cdot 1.5} - \frac{p}{x} \]
      5. cube-div54.3%

        \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot 1.5 - \frac{p}{x} \]
    11. Simplified54.3%

      \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \frac{p}{x}} \]

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

    1. Initial program 100.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. 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-*r*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. *-commutative100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.98:\\ \;\;\;\;{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \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} \]

Alternative 2: 99.9% accurate, 0.7× speedup?

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

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


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

    1. Initial program 16.8%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. add-log-exp16.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. +-commutative16.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-sqrt16.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-def16.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-*r*16.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. *-commutative16.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + -0.25 \cdot \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}}} \]
    7. Step-by-step derivation
      1. +-commutative44.8%

        \[\leadsto \color{blue}{-0.25 \cdot \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. fma-def44.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{-4 \cdot {p}^{4} + -2 \cdot {p}^{4}}{p \cdot {x}^{3}}, -1 \cdot \frac{p}{x}\right)} \]
      3. distribute-rgt-out44.8%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{\color{blue}{{p}^{4} \cdot \left(-4 + -2\right)}}{p \cdot {x}^{3}}, -1 \cdot \frac{p}{x}\right) \]
      4. times-frac48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \color{blue}{\frac{{p}^{4}}{p} \cdot \frac{-4 + -2}{{x}^{3}}}, -1 \cdot \frac{p}{x}\right) \]
      5. metadata-eval48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{\color{blue}{-6}}{{x}^{3}}, -1 \cdot \frac{p}{x}\right) \]
      6. associate-*r/48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \color{blue}{\frac{-1 \cdot p}{x}}\right) \]
      7. mul-1-neg48.1%

        \[\leadsto \mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \frac{\color{blue}{-p}}{x}\right) \]
    8. Simplified48.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{{p}^{4}}{p} \cdot \frac{-6}{{x}^{3}}, \frac{-p}{x}\right)} \]
    9. Taylor expanded in p around 0 51.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x} + 1.5 \cdot \frac{{p}^{3}}{{x}^{3}}} \]
    10. Step-by-step derivation
      1. +-commutative51.2%

        \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}} + -1 \cdot \frac{p}{x}} \]
      2. mul-1-neg51.2%

        \[\leadsto 1.5 \cdot \frac{{p}^{3}}{{x}^{3}} + \color{blue}{\left(-\frac{p}{x}\right)} \]
      3. unsub-neg51.2%

        \[\leadsto \color{blue}{1.5 \cdot \frac{{p}^{3}}{{x}^{3}} - \frac{p}{x}} \]
      4. *-commutative51.2%

        \[\leadsto \color{blue}{\frac{{p}^{3}}{{x}^{3}} \cdot 1.5} - \frac{p}{x} \]
      5. cube-div54.3%

        \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3}} \cdot 1.5 - \frac{p}{x} \]
    11. Simplified54.3%

      \[\leadsto \color{blue}{{\left(\frac{p}{x}\right)}^{3} \cdot 1.5 - \frac{p}{x}} \]

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

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}}\right)} \]
      5. sqr-neg100.0%

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 + \frac{0.5 \cdot x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

        \[\leadsto \sqrt{0.5 + \frac{x}{\sqrt{\color{blue}{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot 0.5} \]
      6. distribute-rgt1-in100.0%

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

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

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

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

Alternative 3: 81.6% accurate, 1.8× speedup?

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

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


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

    1. Initial program 39.9%

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

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}}\right)} \]
      5. sqr-neg39.9%

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}}\right)} \]
      8. distribute-lft-in39.9%

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

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

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

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

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

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

    if -3900 < x

    1. Initial program 92.0%

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

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

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

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

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

Alternative 4: 67.1% accurate, 2.0× speedup?

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

\mathbf{elif}\;x \leq 4.4 \cdot 10^{-26}:\\
\;\;\;\;\sqrt{0.5}\\

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


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

    1. Initial program 39.9%

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

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

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}}\right)} \]
      5. sqr-neg39.9%

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

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right)} + x \cdot x}}\right)} \]
      8. distribute-lft-in39.9%

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

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

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

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

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

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

    if -2550 < x < 4.4000000000000002e-26

    1. Initial program 85.3%

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

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

    if 4.4000000000000002e-26 < x

    1. Initial program 100.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. 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-*r*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. *-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2550:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-26}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 5: 55.0% accurate, 35.5× speedup?

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

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


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

    1. Initial program 51.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    6. Simplified33.0%

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

    if -2.84999999999999982e-136 < x

    1. Initial program 100.0%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. 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-*r*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. *-commutative100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 35.6% accurate, 215.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto 1 \]

Developer target: 79.4% 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 2023293 
(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))))))))