Given's Rotation SVD example

Percentage Accurate: 79.4% → 99.6%
Time: 13.0s
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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} p_m = \left|p\right| \\ \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.98:\\ \;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\ \mathbf{else}:\\ \;\;\;\;{\left({\left(\mathsf{fma}\left(x, \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, 0.5\right)\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.98)
   (/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- x))
   (pow
    (pow (fma x (/ 0.5 (hypot x (* p_m 2.0))) 0.5) 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.98) {
		tmp = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -x;
	} else {
		tmp = pow(pow(fma(x, (0.5 / hypot(x, (p_m * 2.0))), 0.5), 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.98)
		tmp = Float64(Float64(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-x));
	else
		tmp = (fma(x, Float64(0.5 / hypot(x, Float64(p_m * 2.0))), 0.5) ^ 1.5) ^ 0.3333333333333333;
	end
	return 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.98], N[(N[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[Power[N[Power[N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 0.5), $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.98:\\
\;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\

\mathbf{else}:\\
\;\;\;\;{\left({\left(\mathsf{fma}\left(x, \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, 0.5\right)\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 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.97999999999999998

    1. Initial program 12.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. +-commutative12.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. associate-*l*12.8%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define12.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)} \]
      4. sqr-neg12.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)} \]
      5. fma-define12.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)} \]
      6. associate-*l*12.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)} \]
      7. +-commutative12.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)}} \]
      8. distribute-lft-in12.8%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified12.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. Step-by-step derivation
      1. associate-*r/12.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/39.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}{x}} \]
      2. mul-1-neg39.8%

        \[\leadsto \frac{\color{blue}{-\left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}}{x} \]
      3. distribute-rgt-out39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{\color{blue}{{p}^{4} \cdot \left(-16 + 4\right)}}{p \cdot {x}^{2}}\right)}{x} \]
      4. metadata-eval39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot \color{blue}{-12}}{p \cdot {x}^{2}}\right)}{x} \]
    11. Simplified39.8%

      \[\leadsto \color{blue}{\frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot -12}{p \cdot {x}^{2}}\right)}{x}} \]
    12. Taylor expanded in p around 0 47.5%

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

    if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x))))

    1. Initial program 100.0%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define100.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)} \]
      4. 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)} \]
      5. fma-define100.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)} \]
      6. 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)} \]
      7. +-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)}} \]
      8. distribute-lft-in100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 + 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. associate-*r/100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.6% 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.98:\\ \;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x, \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, 0.5\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.98)
   (/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- x))
   (sqrt (fma x (/ 0.5 (hypot x (* p_m 2.0))) 0.5))))
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.98) {
		tmp = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -x;
	} else {
		tmp = sqrt(fma(x, (0.5 / hypot(x, (p_m * 2.0))), 0.5));
	}
	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.98)
		tmp = Float64(Float64(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-x));
	else
		tmp = sqrt(fma(x, Float64(0.5 / hypot(x, Float64(p_m * 2.0))), 0.5));
	end
	return 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.98], N[(N[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[Sqrt[N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 0.5), $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.98:\\
\;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\

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


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

    1. Initial program 12.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. +-commutative12.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. associate-*l*12.8%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define12.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)} \]
      4. sqr-neg12.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)} \]
      5. fma-define12.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)} \]
      6. associate-*l*12.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)} \]
      7. +-commutative12.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)}} \]
      8. distribute-lft-in12.8%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified12.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. Step-by-step derivation
      1. associate-*r/12.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/39.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}{x}} \]
      2. mul-1-neg39.8%

        \[\leadsto \frac{\color{blue}{-\left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}}{x} \]
      3. distribute-rgt-out39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{\color{blue}{{p}^{4} \cdot \left(-16 + 4\right)}}{p \cdot {x}^{2}}\right)}{x} \]
      4. metadata-eval39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot \color{blue}{-12}}{p \cdot {x}^{2}}\right)}{x} \]
    11. Simplified39.8%

      \[\leadsto \color{blue}{\frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot -12}{p \cdot {x}^{2}}\right)}{x}} \]
    12. Taylor expanded in p around 0 47.5%

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

    if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x))))

    1. Initial program 100.0%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define100.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)} \]
      4. 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)} \]
      5. fma-define100.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)} \]
      6. 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)} \]
      7. +-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)}} \]
      8. distribute-lft-in100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 + 0.5 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}} \]
    4. Add Preprocessing
    5. Applied egg-rr66.4%

      \[\leadsto \sqrt{\color{blue}{\frac{\left(1 - {\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}^{2}\right) \cdot 0.5}{1 - \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}}} \]
    6. Step-by-step derivation
      1. *-un-lft-identity66.4%

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

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

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

        \[\leadsto 1 \cdot \sqrt{\color{blue}{\frac{0.5}{1} \cdot \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)}}}} \]
      5. metadata-eval66.4%

        \[\leadsto 1 \cdot \sqrt{\color{blue}{0.5} \cdot \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)}}} \]
      6. metadata-eval66.4%

        \[\leadsto 1 \cdot \sqrt{0.5 \cdot \frac{\color{blue}{1 \cdot 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)}}} \]
      7. unpow266.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.6% 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.98:\\ \;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\ \end{array} \end{array} \]
p_m = (fabs.f64 p)
(FPCore (p_m x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.98)
   (/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- x))
   (sqrt (+ 0.5 (/ (* x 0.5) (hypot x (* p_m 2.0)))))))
p_m = fabs(p);
double code(double p_m, double x) {
	double tmp;
	if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98) {
		tmp = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -x;
	} else {
		tmp = sqrt((0.5 + ((x * 0.5) / hypot(x, (p_m * 2.0)))));
	}
	return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
	double tmp;
	if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98) {
		tmp = (p_m + (-1.5 * (Math.pow(p_m, 3.0) / Math.pow(x, 2.0)))) / -x;
	} else {
		tmp = Math.sqrt((0.5 + ((x * 0.5) / Math.hypot(x, (p_m * 2.0)))));
	}
	return tmp;
}
p_m = math.fabs(p)
def code(p_m, x):
	tmp = 0
	if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98:
		tmp = (p_m + (-1.5 * (math.pow(p_m, 3.0) / math.pow(x, 2.0)))) / -x
	else:
		tmp = math.sqrt((0.5 + ((x * 0.5) / math.hypot(x, (p_m * 2.0)))))
	return tmp
p_m = abs(p)
function code(p_m, x)
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.98)
		tmp = Float64(Float64(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-x));
	else
		tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.5) / hypot(x, Float64(p_m * 2.0)))));
	end
	return tmp
end
p_m = abs(p);
function tmp_2 = code(p_m, x)
	tmp = 0.0;
	if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98)
		tmp = (p_m + (-1.5 * ((p_m ^ 3.0) / (x ^ 2.0)))) / -x;
	else
		tmp = sqrt((0.5 + ((x * 0.5) / hypot(x, (p_m * 2.0)))));
	end
	tmp_2 = tmp;
end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.98], N[(N[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(N[(x * 0.5), $MachinePrecision] / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $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.98:\\
\;\;\;\;\frac{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\

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


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

    1. Initial program 12.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. +-commutative12.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. associate-*l*12.8%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define12.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)} \]
      4. sqr-neg12.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)} \]
      5. fma-define12.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)} \]
      6. associate-*l*12.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)} \]
      7. +-commutative12.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)}} \]
      8. distribute-lft-in12.8%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified12.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. Step-by-step derivation
      1. associate-*r/12.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}}{x}} \]
    10. Step-by-step derivation
      1. associate-*r/39.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}{x}} \]
      2. mul-1-neg39.8%

        \[\leadsto \frac{\color{blue}{-\left(p + 0.125 \cdot \frac{-16 \cdot {p}^{4} + 4 \cdot {p}^{4}}{p \cdot {x}^{2}}\right)}}{x} \]
      3. distribute-rgt-out39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{\color{blue}{{p}^{4} \cdot \left(-16 + 4\right)}}{p \cdot {x}^{2}}\right)}{x} \]
      4. metadata-eval39.8%

        \[\leadsto \frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot \color{blue}{-12}}{p \cdot {x}^{2}}\right)}{x} \]
    11. Simplified39.8%

      \[\leadsto \color{blue}{\frac{-\left(p + 0.125 \cdot \frac{{p}^{4} \cdot -12}{p \cdot {x}^{2}}\right)}{x}} \]
    12. Taylor expanded in p around 0 47.5%

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

    if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x))))

    1. Initial program 100.0%

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

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define100.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)} \]
      4. 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)} \]
      5. fma-define100.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)} \]
      6. 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)} \]
      7. +-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)}} \]
      8. distribute-lft-in100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5 + 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. associate-*r/100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -740:\\
\;\;\;\;\frac{p\_m}{-x}\\

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


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

    1. Initial program 48.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. +-commutative48.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. associate-*l*48.6%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define48.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)} \]
      4. sqr-neg48.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)} \]
      5. fma-define48.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)} \]
      6. associate-*l*48.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)} \]
      7. +-commutative48.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)}} \]
      8. distribute-lft-in48.6%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified48.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 32.3%

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

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

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

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

    if -740 < x

    1. Initial program 87.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. +-commutative87.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. associate-*l*87.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define87.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)} \]
      4. sqr-neg87.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)} \]
      5. fma-define87.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)} \]
      6. associate-*l*87.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)} \]
      7. +-commutative87.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)}} \]
      8. distribute-lft-in87.0%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified87.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. Step-by-step derivation
      1. associate-*r/87.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 69.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 3.4 \cdot 10^{-183}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 4.8 \cdot 10^{-68}:\\
\;\;\;\;\frac{1}{\left|\frac{x}{p\_m}\right|}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 3.40000000000000014e-183

    1. Initial program 74.3%

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

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

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

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

        \[\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)} \]
      5. fma-define74.3%

        \[\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)} \]
      6. associate-*l*74.3%

        \[\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)} \]
      7. +-commutative74.3%

        \[\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)}} \]
      8. distribute-lft-in74.3%

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

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

      \[\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. Applied egg-rr44.0%

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

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

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

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

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

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

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

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

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

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

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

    if 3.40000000000000014e-183 < p < 4.79999999999999982e-68

    1. Initial program 52.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. +-commutative52.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. associate-*l*52.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define52.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)} \]
      4. sqr-neg52.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)} \]
      5. fma-define52.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)} \]
      6. associate-*l*52.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)} \]
      7. +-commutative52.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)}} \]
      8. distribute-lft-in52.4%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified52.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 52.5%

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

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

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

      \[\leadsto \color{blue}{\frac{p}{-x}} \]
    8. Step-by-step derivation
      1. clear-num52.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{-x}{p}}} \]
      2. inv-pow52.2%

        \[\leadsto \color{blue}{{\left(\frac{-x}{p}\right)}^{-1}} \]
      3. add-sqr-sqrt51.2%

        \[\leadsto {\left(\frac{\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}}{p}\right)}^{-1} \]
      4. sqrt-unprod53.6%

        \[\leadsto {\left(\frac{\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}}{p}\right)}^{-1} \]
      5. sqr-neg53.6%

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

        \[\leadsto {\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{p}\right)}^{-1} \]
      7. add-sqr-sqrt4.2%

        \[\leadsto {\left(\frac{\color{blue}{x}}{p}\right)}^{-1} \]
    9. Applied egg-rr4.2%

      \[\leadsto \color{blue}{{\left(\frac{x}{p}\right)}^{-1}} \]
    10. Step-by-step derivation
      1. unpow-14.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{p}}} \]
    11. Simplified4.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{p}}} \]
    12. Step-by-step derivation
      1. add-sqr-sqrt2.2%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{x}{p}} \cdot \sqrt{\frac{x}{p}}}} \]
      2. sqrt-unprod37.1%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{x}{p} \cdot \frac{x}{p}}}} \]
      3. pow237.1%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{{\left(\frac{x}{p}\right)}^{2}}}} \]
    13. Applied egg-rr37.1%

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{x}{p} \cdot \frac{x}{p}}}} \]
      2. rem-sqrt-square53.6%

        \[\leadsto \frac{1}{\color{blue}{\left|\frac{x}{p}\right|}} \]
    15. Simplified53.6%

      \[\leadsto \frac{1}{\color{blue}{\left|\frac{x}{p}\right|}} \]

    if 4.79999999999999982e-68 < p

    1. Initial program 91.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 81.1%

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 69.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 2.8 \cdot 10^{-183}:\\
\;\;\;\;1\\

\mathbf{elif}\;p\_m \leq 1.6 \cdot 10^{-66}:\\
\;\;\;\;\frac{p\_m}{-x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if p < 2.79999999999999985e-183

    1. Initial program 74.3%

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

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

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

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

        \[\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)} \]
      5. fma-define74.3%

        \[\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)} \]
      6. associate-*l*74.3%

        \[\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)} \]
      7. +-commutative74.3%

        \[\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)}} \]
      8. distribute-lft-in74.3%

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

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

      \[\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. Applied egg-rr44.0%

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

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

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

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

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

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

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

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

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

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

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

    if 2.79999999999999985e-183 < p < 1.59999999999999991e-66

    1. Initial program 52.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. +-commutative52.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. associate-*l*52.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define52.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)} \]
      4. sqr-neg52.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)} \]
      5. fma-define52.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)} \]
      6. associate-*l*52.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)} \]
      7. +-commutative52.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)}} \]
      8. distribute-lft-in52.4%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified52.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 52.5%

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

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

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

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

    if 1.59999999999999991e-66 < p

    1. Initial program 91.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 81.1%

      \[\leadsto \color{blue}{\sqrt{0.5}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 54.6% accurate, 23.8× speedup?

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

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

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


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

    1. Initial program 55.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. +-commutative55.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. associate-*l*55.4%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define55.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)} \]
      4. sqr-neg55.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)} \]
      5. fma-define55.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)} \]
      6. associate-*l*55.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)} \]
      7. +-commutative55.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)}} \]
      8. distribute-lft-in55.4%

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

        \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
    3. Simplified55.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 25.9%

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

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

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

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

    if -9.50000000000000008e-211 < 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. associate-*l*100.0%

        \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
      3. fma-define100.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)} \]
      4. 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)} \]
      5. fma-define100.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)} \]
      6. 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)} \]
      7. +-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)}} \]
      8. distribute-lft-in100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 35.1% accurate, 215.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 76.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. +-commutative76.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. associate-*l*76.8%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
    3. fma-define76.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)} \]
    4. sqr-neg76.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)} \]
    5. fma-define76.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)} \]
    6. associate-*l*76.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)} \]
    7. +-commutative76.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)}} \]
    8. distribute-lft-in76.8%

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

      \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
  3. Simplified76.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. Applied egg-rr52.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  11. Add Preprocessing

Alternative 9: 6.2% accurate, 215.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 76.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. +-commutative76.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. associate-*l*76.8%

      \[\leadsto \sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)} + x \cdot x}} + 1\right)} \]
    3. fma-define76.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)} \]
    4. sqr-neg76.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)} \]
    5. fma-define76.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)} \]
    6. associate-*l*76.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)} \]
    7. +-commutative76.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)}} \]
    8. distribute-lft-in76.8%

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

      \[\leadsto \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{x}{\sqrt{\left(4 \cdot \left(-p\right)\right) \cdot \left(-p\right) + x \cdot x}}} \]
  3. Simplified76.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. Applied egg-rr52.2%

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

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

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

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

    \[\leadsto \color{blue}{1} - 1 \]
  9. Step-by-step derivation
    1. metadata-eval5.5%

      \[\leadsto \color{blue}{0} \]
  10. Applied egg-rr5.5%

    \[\leadsto \color{blue}{0} \]
  11. Add Preprocessing

Developer Target 1: 79.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}} \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x))))))
double code(double p, double x) {
	return sqrt((0.5 + (copysign(0.5, x) / hypot(1.0, ((2.0 * p) / x)))));
}
public static double code(double p, double x) {
	return Math.sqrt((0.5 + (Math.copySign(0.5, x) / Math.hypot(1.0, ((2.0 * p) / x)))));
}
def code(p, x):
	return math.sqrt((0.5 + (math.copysign(0.5, x) / math.hypot(1.0, ((2.0 * p) / x)))))
function code(p, x)
	return sqrt(Float64(0.5 + Float64(copysign(0.5, x) / hypot(1.0, Float64(Float64(2.0 * p) / x)))))
end
function tmp = code(p, x)
	tmp = sqrt((0.5 + ((sign(x) * abs(0.5)) / hypot(1.0, ((2.0 * p) / x)))));
end
code[p_, x_] := N[Sqrt[N[(0.5 + N[(N[With[{TMP1 = Abs[0.5], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + N[(N[(2.0 * p), $MachinePrecision] / x), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}
\end{array}

Reproduce

?
herbie shell --seed 2024172 
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))

  :alt
  (! :herbie-platform default (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x))))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))