Given's Rotation SVD example

Percentage Accurate: 79.6% → 99.9%
Time: 9.2s
Alternatives: 5
Speedup: 0.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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


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

    1. Initial program 15.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    6. Step-by-step derivation
      1. unpow1/315.4%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg62.6%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac62.6%

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 68.6% accurate, 2.1× speedup?

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

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


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

    1. Initial program 79.8%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt79.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-def79.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*79.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-prod79.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-eval79.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-unprod17.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    6. Step-by-step derivation
      1. unpow1/379.8%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg16.7%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac16.7%

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

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

    if 1.60000000000000006e-41 < p

    1. Initial program 91.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.6 \cdot 10^{-41}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 3: 69.2% accurate, 2.1× speedup?

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

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


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

    1. Initial program 79.9%

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

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

    if 1.9500000000000001e-31 < p

    1. Initial program 91.4%

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

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

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

Alternative 4: 28.6% accurate, 35.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{p}{x}\\


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

    1. Initial program 64.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    6. Step-by-step derivation
      1. unpow1/364.1%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    9. Step-by-step derivation
      1. mul-1-neg28.2%

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
      2. distribute-neg-frac28.2%

        \[\leadsto \color{blue}{\frac{-p}{x}} \]
    10. Simplified28.2%

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

    if -4.999999999999985e-310 < 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-sqr-sqrt100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    6. Step-by-step derivation
      1. unpow1/3100.0%

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

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

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

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

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

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

        \[\leadsto \sqrt[3]{{\left(p \cdot \frac{p}{\color{blue}{x \cdot x}}\right)}^{1.5}} \]
      4. associate-/r*4.6%

        \[\leadsto \sqrt[3]{{\left(p \cdot \color{blue}{\frac{\frac{p}{x}}{x}}\right)}^{1.5}} \]
    10. Simplified4.6%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(p \cdot \frac{\frac{p}{x}}{x}\right)}}^{1.5}} \]
    11. Taylor expanded in p around 0 3.3%

      \[\leadsto \color{blue}{\frac{p}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.3%

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

Alternative 5: 6.7% accurate, 71.7× speedup?

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

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  2. Step-by-step derivation
    1. add-sqr-sqrt82.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-def82.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*82.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-prod82.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-eval82.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-unprod36.2%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{\left({\left(0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(2 \cdot p, x\right)}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
  6. Step-by-step derivation
    1. unpow1/382.7%

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{{\left(p \cdot \frac{p}{\color{blue}{x \cdot x}}\right)}^{1.5}} \]
    4. associate-/r*14.0%

      \[\leadsto \sqrt[3]{{\left(p \cdot \color{blue}{\frac{\frac{p}{x}}{x}}\right)}^{1.5}} \]
  10. Simplified14.0%

    \[\leadsto \sqrt[3]{{\color{blue}{\left(p \cdot \frac{\frac{p}{x}}{x}\right)}}^{1.5}} \]
  11. Taylor expanded in p around 0 12.8%

    \[\leadsto \color{blue}{\frac{p}{x}} \]
  12. Final simplification12.8%

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

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 2023240 
(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))))))))