Given's Rotation SVD example

Percentage Accurate: 98.7% → 98.7%
Time: 21.4s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 98.7% 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: 98.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}} \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (* 0.5 (exp (log1p (/ x (hypot x (* p 2.0))))))))
double code(double p, double x) {
	return sqrt((0.5 * exp(log1p((x / hypot(x, (p * 2.0)))))));
}
public static double code(double p, double x) {
	return Math.sqrt((0.5 * Math.exp(Math.log1p((x / Math.hypot(x, (p * 2.0)))))));
}
def code(p, x):
	return math.sqrt((0.5 * math.exp(math.log1p((x / math.hypot(x, (p * 2.0)))))))
function code(p, x)
	return sqrt(Float64(0.5 * exp(log1p(Float64(x / hypot(x, Float64(p * 2.0)))))))
end
code[p_, x_] := N[Sqrt[N[(0.5 * N[Exp[N[Log[1 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}}
\end{array}
Derivation
  1. Initial program 98.4%

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-exp-log98.4%

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

      \[\leadsto \sqrt{0.5 \cdot e^{\color{blue}{\mathsf{log1p}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]
    3. div-inv95.1%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\color{blue}{x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}} \]
    4. +-commutative95.1%

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

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

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(x \cdot \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}\right)}} \]
    7. div-inv98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\color{blue}{\frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}\right)}} \]
    8. fma-undefine98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{\color{blue}{x \cdot x + 4 \cdot \left(p \cdot p\right)}}}\right)}} \]
    9. associate-*r*98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{x \cdot x + \color{blue}{\left(4 \cdot p\right) \cdot p}}}\right)}} \]
    10. add-sqr-sqrt98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{x \cdot x + \color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p} \cdot \sqrt{\left(4 \cdot p\right) \cdot p}}}}\right)}} \]
    11. hypot-define98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\color{blue}{\mathsf{hypot}\left(x, \sqrt{\left(4 \cdot p\right) \cdot p}\right)}}\right)}} \]
    12. associate-*r*98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)}}\right)}\right)}} \]
    13. *-commutative98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(p \cdot p\right) \cdot 4}}\right)}\right)}} \]
    14. sqrt-prod98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\sqrt{p \cdot p} \cdot \sqrt{4}}\right)}\right)}} \]
    15. sqrt-prod48.7%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)} \cdot \sqrt{4}\right)}\right)}} \]
    16. add-sqr-sqrt98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{p} \cdot \sqrt{4}\right)}\right)}} \]
    17. metadata-eval98.5%

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

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}}} \]
  5. Final simplification98.5%

    \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}} \]
  6. Add Preprocessing

Alternative 2: 98.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ {\left({\left(0.5 \cdot \left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} + 1\right)\right)}^{1.5}\right)}^{0.3333333333333333} \end{array} \]
(FPCore (p x)
 :precision binary64
 (pow (pow (* 0.5 (+ (/ x (hypot x (* p 2.0))) 1.0)) 1.5) 0.3333333333333333))
double code(double p, double x) {
	return pow(pow((0.5 * ((x / hypot(x, (p * 2.0))) + 1.0)), 1.5), 0.3333333333333333);
}
public static double code(double p, double x) {
	return Math.pow(Math.pow((0.5 * ((x / Math.hypot(x, (p * 2.0))) + 1.0)), 1.5), 0.3333333333333333);
}
def code(p, x):
	return math.pow(math.pow((0.5 * ((x / math.hypot(x, (p * 2.0))) + 1.0)), 1.5), 0.3333333333333333)
function code(p, x)
	return (Float64(0.5 * Float64(Float64(x / hypot(x, Float64(p * 2.0))) + 1.0)) ^ 1.5) ^ 0.3333333333333333
end
function tmp = code(p, x)
	tmp = ((0.5 * ((x / hypot(x, (p * 2.0))) + 1.0)) ^ 1.5) ^ 0.3333333333333333;
end
code[p_, x_] := N[Power[N[Power[N[(0.5 * N[(N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $MachinePrecision]
\begin{array}{l}

\\
{\left({\left(0.5 \cdot \left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} + 1\right)\right)}^{1.5}\right)}^{0.3333333333333333}
\end{array}
Derivation
  1. Initial program 98.4%

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-exp-log98.4%

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

      \[\leadsto \sqrt{0.5 \cdot e^{\color{blue}{\mathsf{log1p}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]
    3. div-inv95.1%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\color{blue}{x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}} \]
    4. +-commutative95.1%

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

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

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(x \cdot \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}\right)}} \]
    7. div-inv98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\color{blue}{\frac{x}{\sqrt{\mathsf{fma}\left(x, x, 4 \cdot \left(p \cdot p\right)\right)}}}\right)}} \]
    8. fma-undefine98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{\color{blue}{x \cdot x + 4 \cdot \left(p \cdot p\right)}}}\right)}} \]
    9. associate-*r*98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{x \cdot x + \color{blue}{\left(4 \cdot p\right) \cdot p}}}\right)}} \]
    10. add-sqr-sqrt98.4%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{x \cdot x + \color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p} \cdot \sqrt{\left(4 \cdot p\right) \cdot p}}}}\right)}} \]
    11. hypot-define98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\color{blue}{\mathsf{hypot}\left(x, \sqrt{\left(4 \cdot p\right) \cdot p}\right)}}\right)}} \]
    12. associate-*r*98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{\color{blue}{4 \cdot \left(p \cdot p\right)}}\right)}\right)}} \]
    13. *-commutative98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{\color{blue}{\left(p \cdot p\right) \cdot 4}}\right)}\right)}} \]
    14. sqrt-prod98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\sqrt{p \cdot p} \cdot \sqrt{4}}\right)}\right)}} \]
    15. sqrt-prod48.7%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\left(\sqrt{p} \cdot \sqrt{p}\right)} \cdot \sqrt{4}\right)}\right)}} \]
    16. add-sqr-sqrt98.5%

      \[\leadsto \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{p} \cdot \sqrt{4}\right)}\right)}} \]
    17. metadata-eval98.5%

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

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

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

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

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

    \[\leadsto {\left({\left(0.5 \cdot \left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)} + 1\right)\right)}^{1.5}\right)}^{0.3333333333333333} \]
  8. Add Preprocessing

Alternative 3: 98.7% accurate, 1.0× speedup?

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

\\
\sqrt{0.5 + \frac{0.5 \cdot x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}
\end{array}
Derivation
  1. Initial program 98.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. +-commutative98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt{0.5 + \frac{0.5 \cdot x}{\mathsf{hypot}\left(x, p \cdot 2\right)}} \]
  8. Add Preprocessing

Alternative 4: 45.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;p \leq 7 \cdot 10^{-7}:\\
\;\;\;\;\left(1 - \frac{p}{x}\right) + -1\\

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


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

    1. Initial program 97.9%

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

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

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

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

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

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

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

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

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

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

      \[\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. *-commutative97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{p}{x}\right)} - 1 \]
    10. Step-by-step derivation
      1. mul-1-neg34.3%

        \[\leadsto \left(1 + \color{blue}{\left(-\frac{p}{x}\right)}\right) - 1 \]
      2. unsub-neg34.3%

        \[\leadsto \color{blue}{\left(1 - \frac{p}{x}\right)} - 1 \]
    11. Simplified34.3%

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

    if 6.99999999999999968e-7 < p

    1. Initial program 99.8%

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

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

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

Alternative 5: 25.8% accurate, 30.7× speedup?

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

\\
\left(1 - \frac{p}{x}\right) + -1
\end{array}
Derivation
  1. Initial program 98.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. +-commutative98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{p}{x}\right)} - 1 \]
  10. Step-by-step derivation
    1. mul-1-neg26.8%

      \[\leadsto \left(1 + \color{blue}{\left(-\frac{p}{x}\right)}\right) - 1 \]
    2. unsub-neg26.8%

      \[\leadsto \color{blue}{\left(1 - \frac{p}{x}\right)} - 1 \]
  11. Simplified26.8%

    \[\leadsto \color{blue}{\left(1 - \frac{p}{x}\right)} - 1 \]
  12. Final simplification26.8%

    \[\leadsto \left(1 - \frac{p}{x}\right) + -1 \]
  13. Add Preprocessing

Alternative 6: 7.0% accurate, 53.8× speedup?

\[\begin{array}{l} \\ \frac{p}{-x} \end{array} \]
(FPCore (p x) :precision binary64 (/ p (- x)))
double code(double p, double x) {
	return p / -x;
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    code = p / -x
end function
public static double code(double p, double x) {
	return p / -x;
}
def code(p, x):
	return p / -x
function code(p, x)
	return Float64(p / Float64(-x))
end
function tmp = code(p, x)
	tmp = p / -x;
end
code[p_, x_] := N[(p / (-x)), $MachinePrecision]
\begin{array}{l}

\\
\frac{p}{-x}
\end{array}
Derivation
  1. Initial program 98.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. +-commutative98.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Developer target: 98.7% 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 2024045 
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

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