Given's Rotation SVD example

Percentage Accurate: 79.5% → 99.8%
Time: 11.9s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 79.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.99998:\\
\;\;\;\;\frac{-p\_m}{x}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left({t\_0}^{2}, 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)))) < -0.99997999999999998

    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. +-commutative15.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified58.0%

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

    if -0.99997999999999998 < (/.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. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative99.9%

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.5× speedup?

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

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

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


\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.99997999999999998

    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. +-commutative15.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified58.0%

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

    if -0.99997999999999998 < (/.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. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.8% accurate, 0.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\frac{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}{x}}\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.99997999999999998

    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. +-commutative15.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified58.0%

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

    if -0.99997999999999998 < (/.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. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 82.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+37}:\\
\;\;\;\;\frac{-p\_m}{x}\\

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


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

    1. Initial program 43.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. +-commutative43.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified41.0%

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

    if -1.99999999999999991e37 < x

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 69.5% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
\mathbf{if}\;p\_m \leq 7.2 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 1.4 \cdot 10^{-141}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\

\mathbf{elif}\;p\_m \leq 2.1 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 4.8 \cdot 10^{-79}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 7.1999999999999994e-188 or 1.40000000000000006e-141 < p < 2.1e-119

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified17.1%

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

    if 7.1999999999999994e-188 < p < 1.40000000000000006e-141

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative73.4%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified73.4%

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

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow273.4%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac73.4%

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

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

    if 2.1e-119 < p < 4.80000000000000011e-79

    1. Initial program 81.0%

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

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

    if 4.80000000000000011e-79 < p

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(1 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right) \cdot 0.5}} \]
    7. Step-by-step derivation
      1. clear-num86.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 7.2 \cdot 10^{-188}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 1.4 \cdot 10^{-141}:\\ \;\;\;\;1 + \left(\frac{p}{x} \cdot \frac{p}{x}\right) \cdot -0.5\\ \mathbf{elif}\;p \leq 2.1 \cdot 10^{-119}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 4.8 \cdot 10^{-79}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{0.25 \cdot \frac{x}{p} + \frac{p}{x} \cdot 2}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 68.8% accurate, 1.8× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} t_0 := \frac{-p\_m}{x}\\ t_1 := 1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\ \mathbf{if}\;p\_m \leq 1.05 \cdot 10^{-188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;p\_m \leq 4 \cdot 10^{-141}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;p\_m \leq 2.36 \cdot 10^{-119}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;p\_m \leq 2.35 \cdot 10^{-81}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (let* ((t_0 (/ (- p_m) x)) (t_1 (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))))
   (if (<= p_m 1.05e-188)
     t_0
     (if (<= p_m 4e-141)
       t_1
       (if (<= p_m 2.36e-119) t_0 (if (<= p_m 2.35e-81) t_1 (sqrt 0.5)))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double t_0 = -p_m / x;
	double t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
	double tmp;
	if (p_m <= 1.05e-188) {
		tmp = t_0;
	} else if (p_m <= 4e-141) {
		tmp = t_1;
	} else if (p_m <= 2.36e-119) {
		tmp = t_0;
	} else if (p_m <= 2.35e-81) {
		tmp = t_1;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
    real(8), intent (in) :: p_m
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -p_m / x
    t_1 = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
    if (p_m <= 1.05d-188) then
        tmp = t_0
    else if (p_m <= 4d-141) then
        tmp = t_1
    else if (p_m <= 2.36d-119) then
        tmp = t_0
    else if (p_m <= 2.35d-81) then
        tmp = t_1
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double t_0 = -p_m / x;
	double t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
	double tmp;
	if (p_m <= 1.05e-188) {
		tmp = t_0;
	} else if (p_m <= 4e-141) {
		tmp = t_1;
	} else if (p_m <= 2.36e-119) {
		tmp = t_0;
	} else if (p_m <= 2.35e-81) {
		tmp = t_1;
	} else {
		tmp = Math.sqrt(0.5);
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	t_0 = -p_m / x
	t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5)
	tmp = 0
	if p_m <= 1.05e-188:
		tmp = t_0
	elif p_m <= 4e-141:
		tmp = t_1
	elif p_m <= 2.36e-119:
		tmp = t_0
	elif p_m <= 2.35e-81:
		tmp = t_1
	else:
		tmp = math.sqrt(0.5)
	return tmp
p_m = abs(p)
function code(p_m, x)
	t_0 = Float64(Float64(-p_m) / x)
	t_1 = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5))
	tmp = 0.0
	if (p_m <= 1.05e-188)
		tmp = t_0;
	elseif (p_m <= 4e-141)
		tmp = t_1;
	elseif (p_m <= 2.36e-119)
		tmp = t_0;
	elseif (p_m <= 2.35e-81)
		tmp = t_1;
	else
		tmp = sqrt(0.5);
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	t_0 = -p_m / x;
	t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
	tmp = 0.0;
	if (p_m <= 1.05e-188)
		tmp = t_0;
	elseif (p_m <= 4e-141)
		tmp = t_1;
	elseif (p_m <= 2.36e-119)
		tmp = t_0;
	elseif (p_m <= 2.35e-81)
		tmp = t_1;
	else
		tmp = sqrt(0.5);
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p$95$m, 1.05e-188], t$95$0, If[LessEqual[p$95$m, 4e-141], t$95$1, If[LessEqual[p$95$m, 2.36e-119], t$95$0, If[LessEqual[p$95$m, 2.35e-81], t$95$1, N[Sqrt[0.5], $MachinePrecision]]]]]]]
\begin{array}{l}
p_m = \left|p\right|

\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
t_1 := 1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{if}\;p\_m \leq 1.05 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 4 \cdot 10^{-141}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;p\_m \leq 2.36 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 2.35 \cdot 10^{-81}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 1.05e-188 or 4.0000000000000002e-141 < p < 2.35999999999999992e-119

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified17.1%

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

    if 1.05e-188 < p < 4.0000000000000002e-141 or 2.35999999999999992e-119 < p < 2.35000000000000014e-81

    1. Initial program 77.5%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative77.8%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified77.8%

      \[\leadsto \color{blue}{1 + \frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    8. Step-by-step derivation
      1. unpow277.8%

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow277.8%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac77.8%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr77.8%

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

    if 2.35000000000000014e-81 < p

    1. Initial program 86.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 1.05 \cdot 10^{-188}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 4 \cdot 10^{-141}:\\ \;\;\;\;1 + \left(\frac{p}{x} \cdot \frac{p}{x}\right) \cdot -0.5\\ \mathbf{elif}\;p \leq 2.36 \cdot 10^{-119}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 2.35 \cdot 10^{-81}:\\ \;\;\;\;1 + \left(\frac{p}{x} \cdot \frac{p}{x}\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.9% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
\mathbf{if}\;p\_m \leq 2.6 \cdot 10^{-190}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 2.2 \cdot 10^{-141}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\

\mathbf{elif}\;p\_m \leq 2.2 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;p\_m \leq 5.7 \cdot 10^{-79}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if p < 2.5999999999999998e-190 or 2.20000000000000009e-141 < p < 2.2000000000000001e-119

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified17.1%

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

    if 2.5999999999999998e-190 < p < 2.20000000000000009e-141

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative73.4%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified73.4%

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

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow273.4%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac73.4%

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

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

    if 2.2000000000000001e-119 < p < 5.69999999999999957e-79

    1. Initial program 81.0%

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

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

    if 5.69999999999999957e-79 < p

    1. Initial program 86.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 2.6 \cdot 10^{-190}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 2.2 \cdot 10^{-141}:\\ \;\;\;\;1 + \left(\frac{p}{x} \cdot \frac{p}{x}\right) \cdot -0.5\\ \mathbf{elif}\;p \leq 2.2 \cdot 10^{-119}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 5.7 \cdot 10^{-79}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 50.9% accurate, 13.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.5 \cdot 10^{-277}:\\
\;\;\;\;\frac{-p\_m}{x}\\

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


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

    1. Initial program 57.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. +-commutative57.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{p}{x}} \]
    7. Simplified31.0%

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

    if 7.49999999999999971e-277 < 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. +-commutative100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{{p}^{2}}{{x}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative43.7%

        \[\leadsto 1 + \color{blue}{\frac{{p}^{2}}{{x}^{2}} \cdot -0.5} \]
    7. Simplified43.7%

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

        \[\leadsto 1 + \frac{{p}^{2}}{\color{blue}{x \cdot x}} \cdot -0.5 \]
      2. unpow243.7%

        \[\leadsto 1 + \frac{\color{blue}{p \cdot p}}{x \cdot x} \cdot -0.5 \]
      3. times-frac43.7%

        \[\leadsto 1 + \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)} \cdot -0.5 \]
    9. Applied egg-rr43.7%

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

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

Alternative 9: 26.7% accurate, 53.8× speedup?

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

\\
\frac{-p\_m}{x}
\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. +-commutative78.1%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-\frac{p}{x}} \]
  8. Final simplification17.7%

    \[\leadsto \frac{-p}{x} \]
  9. Add Preprocessing

Developer target: 79.5% 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 2024040 
(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))))))))