Given's Rotation SVD example

Percentage Accurate: 79.6% → 90.7%
Time: 19.3s
Alternatives: 8
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 8 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: 90.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}} \cdot \left(-\sqrt{\left(p \cdot p\right) \cdot 6}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{3}}{\mathsf{fma}\left(t_0, \frac{-1 + {t_0}^{2}}{1 + t_0}, 1\right)}}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ x (hypot x (* p 2.0)))))
   (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
     (*
      (/ (sqrt 0.5) (/ x (sqrt 0.3333333333333333)))
      (- (sqrt (* (* p p) 6.0))))
     (sqrt
      (*
       0.5
       (/
        (+ 1.0 (pow t_0 3.0))
        (fma t_0 (/ (+ -1.0 (pow t_0 2.0)) (+ 1.0 t_0)) 1.0)))))))
double code(double p, double x) {
	double t_0 = x / hypot(x, (p * 2.0));
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = (sqrt(0.5) / (x / sqrt(0.3333333333333333))) * -sqrt(((p * p) * 6.0));
	} else {
		tmp = sqrt((0.5 * ((1.0 + pow(t_0, 3.0)) / fma(t_0, ((-1.0 + pow(t_0, 2.0)) / (1.0 + t_0)), 1.0))));
	}
	return tmp;
}
function code(p, x)
	t_0 = Float64(x / hypot(x, Float64(p * 2.0)))
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = Float64(Float64(sqrt(0.5) / Float64(x / sqrt(0.3333333333333333))) * Float64(-sqrt(Float64(Float64(p * p) * 6.0))));
	else
		tmp = sqrt(Float64(0.5 * Float64(Float64(1.0 + (t_0 ^ 3.0)) / fma(t_0, Float64(Float64(-1.0 + (t_0 ^ 2.0)) / Float64(1.0 + t_0)), 1.0))));
	end
	return tmp
end
code[p_, x_] := Block[{t$95$0 = N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(N[Sqrt[0.5], $MachinePrecision] / N[(x / N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sqrt[N[(N[(p * p), $MachinePrecision] * 6.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 + N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(N[(-1.0 + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}} \cdot \left(-\sqrt{\left(p \cdot p\right) \cdot 6}\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{3}}{\mathsf{fma}\left(t_0, \frac{-1 + {t_0}^{2}}{1 + t_0}, 1\right)}}\\


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

    1. Initial program 19.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. flip3-+19.0%

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

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

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

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5} \cdot \sqrt{0.3333333333333333}}{x} \cdot \sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}} \]
      2. distribute-rgt-neg-in64.3%

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

        \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}}} \cdot \left(-\sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}\right) \]
      4. distribute-rgt-out64.3%

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

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

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

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 90.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}} \cdot \left(-\sqrt{\left(p \cdot p\right) \cdot 6}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{3}}{\mathsf{fma}\left(t_0, -1 + t_0, 1\right)}}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ x (hypot x (* p 2.0)))))
   (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
     (*
      (/ (sqrt 0.5) (/ x (sqrt 0.3333333333333333)))
      (- (sqrt (* (* p p) 6.0))))
     (sqrt (* 0.5 (/ (+ 1.0 (pow t_0 3.0)) (fma t_0 (+ -1.0 t_0) 1.0)))))))
double code(double p, double x) {
	double t_0 = x / hypot(x, (p * 2.0));
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = (sqrt(0.5) / (x / sqrt(0.3333333333333333))) * -sqrt(((p * p) * 6.0));
	} else {
		tmp = sqrt((0.5 * ((1.0 + pow(t_0, 3.0)) / fma(t_0, (-1.0 + t_0), 1.0))));
	}
	return tmp;
}
function code(p, x)
	t_0 = Float64(x / hypot(x, Float64(p * 2.0)))
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = Float64(Float64(sqrt(0.5) / Float64(x / sqrt(0.3333333333333333))) * Float64(-sqrt(Float64(Float64(p * p) * 6.0))));
	else
		tmp = sqrt(Float64(0.5 * Float64(Float64(1.0 + (t_0 ^ 3.0)) / fma(t_0, Float64(-1.0 + t_0), 1.0))));
	end
	return tmp
end
code[p_, x_] := Block[{t$95$0 = N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(N[Sqrt[0.5], $MachinePrecision] / N[(x / N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-N[Sqrt[N[(N[(p * p), $MachinePrecision] * 6.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 + N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(-1.0 + t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}} \cdot \left(-\sqrt{\left(p \cdot p\right) \cdot 6}\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{3}}{\mathsf{fma}\left(t_0, -1 + t_0, 1\right)}}\\


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

    1. Initial program 19.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. flip3-+19.0%

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

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

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

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5} \cdot \sqrt{0.3333333333333333}}{x} \cdot \sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}} \]
      2. distribute-rgt-neg-in64.3%

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

        \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}}} \cdot \left(-\sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}\right) \]
      4. distribute-rgt-out64.3%

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

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

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

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

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

    1. Initial program 99.9%

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

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

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

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

Alternative 3: 90.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\left(-\sqrt{\left(p \cdot p\right) \cdot 6}\right) \cdot \frac{\sqrt{0.5} \cdot \sqrt{0.3333333333333333}}{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)))) < -1

    1. Initial program 19.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. flip3-+19.0%

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

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

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

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5} \cdot \sqrt{0.3333333333333333}}{x} \cdot \sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}} \]
      2. distribute-rgt-out64.3%

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

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

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

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

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

    1. Initial program 99.9%

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)}, x\right)}\right)} \]
      7. add-sqr-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 simplification90.3%

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

Alternative 4: 90.7% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 19.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. flip3-+19.0%

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

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

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

        \[\leadsto \color{blue}{-\frac{\sqrt{0.5} \cdot \sqrt{0.3333333333333333}}{x} \cdot \sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}} \]
      2. distribute-rgt-neg-in64.3%

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

        \[\leadsto \color{blue}{\frac{\sqrt{0.5}}{\frac{x}{\sqrt{0.3333333333333333}}}} \cdot \left(-\sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}\right) \]
      4. distribute-rgt-out64.3%

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

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

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

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

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

    1. Initial program 99.9%

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

        \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(2 \cdot \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)}, x\right)}\right)} \]
      7. add-sqr-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 simplification90.3%

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

Alternative 5: 91.3% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 19.0%

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

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

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

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

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

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

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

    1. Initial program 99.9%

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

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

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

Alternative 6: 68.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;p \leq -3.9 \cdot 10^{-34}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq -9.2 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq -3.1 \cdot 10^{-197}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 2.15 \cdot 10^{-265}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 8.4 \cdot 10^{-75}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (if (<= p -3.9e-34)
   (sqrt 0.5)
   (if (<= p -9.2e-125)
     1.0
     (if (<= p -3.1e-197)
       (/ p x)
       (if (<= p 2.15e-265) 1.0 (if (<= p 8.4e-75) (/ (- p) x) (sqrt 0.5)))))))
double code(double p, double x) {
	double tmp;
	if (p <= -3.9e-34) {
		tmp = sqrt(0.5);
	} else if (p <= -9.2e-125) {
		tmp = 1.0;
	} else if (p <= -3.1e-197) {
		tmp = p / x;
	} else if (p <= 2.15e-265) {
		tmp = 1.0;
	} else if (p <= 8.4e-75) {
		tmp = -p / x;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: tmp
    if (p <= (-3.9d-34)) then
        tmp = sqrt(0.5d0)
    else if (p <= (-9.2d-125)) then
        tmp = 1.0d0
    else if (p <= (-3.1d-197)) then
        tmp = p / x
    else if (p <= 2.15d-265) then
        tmp = 1.0d0
    else if (p <= 8.4d-75) then
        tmp = -p / x
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double tmp;
	if (p <= -3.9e-34) {
		tmp = Math.sqrt(0.5);
	} else if (p <= -9.2e-125) {
		tmp = 1.0;
	} else if (p <= -3.1e-197) {
		tmp = p / x;
	} else if (p <= 2.15e-265) {
		tmp = 1.0;
	} else if (p <= 8.4e-75) {
		tmp = -p / x;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
def code(p, x):
	tmp = 0
	if p <= -3.9e-34:
		tmp = math.sqrt(0.5)
	elif p <= -9.2e-125:
		tmp = 1.0
	elif p <= -3.1e-197:
		tmp = p / x
	elif p <= 2.15e-265:
		tmp = 1.0
	elif p <= 8.4e-75:
		tmp = -p / x
	else:
		tmp = math.sqrt(0.5)
	return tmp
function code(p, x)
	tmp = 0.0
	if (p <= -3.9e-34)
		tmp = sqrt(0.5);
	elseif (p <= -9.2e-125)
		tmp = 1.0;
	elseif (p <= -3.1e-197)
		tmp = Float64(p / x);
	elseif (p <= 2.15e-265)
		tmp = 1.0;
	elseif (p <= 8.4e-75)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
function tmp_2 = code(p, x)
	tmp = 0.0;
	if (p <= -3.9e-34)
		tmp = sqrt(0.5);
	elseif (p <= -9.2e-125)
		tmp = 1.0;
	elseif (p <= -3.1e-197)
		tmp = p / x;
	elseif (p <= 2.15e-265)
		tmp = 1.0;
	elseif (p <= 8.4e-75)
		tmp = -p / x;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
code[p_, x_] := If[LessEqual[p, -3.9e-34], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, -9.2e-125], 1.0, If[LessEqual[p, -3.1e-197], N[(p / x), $MachinePrecision], If[LessEqual[p, 2.15e-265], 1.0, If[LessEqual[p, 8.4e-75], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;p \leq -3.9 \cdot 10^{-34}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;p \leq -9.2 \cdot 10^{-125}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq -3.1 \cdot 10^{-197}:\\
\;\;\;\;\frac{p}{x}\\

\mathbf{elif}\;p \leq 2.15 \cdot 10^{-265}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 8.4 \cdot 10^{-75}:\\
\;\;\;\;\frac{-p}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < -3.89999999999999991e-34 or 8.4000000000000004e-75 < 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 84.2%

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

    if -3.89999999999999991e-34 < p < -9.1999999999999996e-125 or -3.10000000000000029e-197 < p < 2.1500000000000001e-265

    1. Initial program 79.6%

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

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

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

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

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

    if -9.1999999999999996e-125 < p < -3.10000000000000029e-197

    1. Initial program 42.0%

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

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

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

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

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

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

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

    if 2.1500000000000001e-265 < p < 8.4000000000000004e-75

    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. Taylor expanded in x around -inf 29.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-p}}{x} \]
    7. Simplified66.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq -3.9 \cdot 10^{-34}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq -9.2 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq -3.1 \cdot 10^{-197}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 2.15 \cdot 10^{-265}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 8.4 \cdot 10^{-75}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternative 7: 44.6% accurate, 42.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-97}:\\
\;\;\;\;\frac{p}{x}\\

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


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

    1. Initial program 57.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 -inf 31.0%

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

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

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

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

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

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

    if -6.39999999999999961e-97 < x

    1. Initial program 96.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-cbrt-cube96.4%

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

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

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

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

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

Alternative 8: 36.2% accurate, 215.0× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  5. Final simplification33.8%

    \[\leadsto 1 \]

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