?

Average Error: 13.1 → 6.0
Time: 15.9s
Precision: binary64
Cost: 87556

?

\[10^{-150} < \left|x\right| \land \left|x\right| < 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
\[\begin{array}{l} t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\ t_1 := 1 + {t_0}^{3}\\ t_2 := {t_0}^{2}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{\sqrt{p \cdot \left(p \cdot 6\right)} \cdot \frac{-\sqrt{0.5}}{x}}{\sqrt{1 + \left(t_2 - t_0\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{t_1}{t_2 + \frac{1 - t_2}{t_1} \cdot \left(t_2 + \left(1 - t_0\right)\right)}}\\ \end{array} \]
(FPCore (p x)
 :precision binary64
 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ x (hypot x (* p 2.0))))
        (t_1 (+ 1.0 (pow t_0 3.0)))
        (t_2 (pow t_0 2.0)))
   (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
     (/
      (* (sqrt (* p (* p 6.0))) (/ (- (sqrt 0.5)) x))
      (sqrt (+ 1.0 (- t_2 t_0))))
     (sqrt
      (* 0.5 (/ t_1 (+ t_2 (* (/ (- 1.0 t_2) t_1) (+ t_2 (- 1.0 t_0))))))))))
double code(double p, double x) {
	return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
double code(double p, double x) {
	double t_0 = x / hypot(x, (p * 2.0));
	double t_1 = 1.0 + pow(t_0, 3.0);
	double t_2 = pow(t_0, 2.0);
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = (sqrt((p * (p * 6.0))) * (-sqrt(0.5) / x)) / sqrt((1.0 + (t_2 - t_0)));
	} else {
		tmp = sqrt((0.5 * (t_1 / (t_2 + (((1.0 - t_2) / t_1) * (t_2 + (1.0 - t_0)))))));
	}
	return tmp;
}
public static double code(double p, double x) {
	return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
public static double code(double p, double x) {
	double t_0 = x / Math.hypot(x, (p * 2.0));
	double t_1 = 1.0 + Math.pow(t_0, 3.0);
	double t_2 = Math.pow(t_0, 2.0);
	double tmp;
	if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
		tmp = (Math.sqrt((p * (p * 6.0))) * (-Math.sqrt(0.5) / x)) / Math.sqrt((1.0 + (t_2 - t_0)));
	} else {
		tmp = Math.sqrt((0.5 * (t_1 / (t_2 + (((1.0 - t_2) / t_1) * (t_2 + (1.0 - t_0)))))));
	}
	return tmp;
}
def code(p, x):
	return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
def code(p, x):
	t_0 = x / math.hypot(x, (p * 2.0))
	t_1 = 1.0 + math.pow(t_0, 3.0)
	t_2 = math.pow(t_0, 2.0)
	tmp = 0
	if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0:
		tmp = (math.sqrt((p * (p * 6.0))) * (-math.sqrt(0.5) / x)) / math.sqrt((1.0 + (t_2 - t_0)))
	else:
		tmp = math.sqrt((0.5 * (t_1 / (t_2 + (((1.0 - t_2) / t_1) * (t_2 + (1.0 - t_0)))))))
	return tmp
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 code(p, x)
	t_0 = Float64(x / hypot(x, Float64(p * 2.0)))
	t_1 = Float64(1.0 + (t_0 ^ 3.0))
	t_2 = t_0 ^ 2.0
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0)
		tmp = Float64(Float64(sqrt(Float64(p * Float64(p * 6.0))) * Float64(Float64(-sqrt(0.5)) / x)) / sqrt(Float64(1.0 + Float64(t_2 - t_0))));
	else
		tmp = sqrt(Float64(0.5 * Float64(t_1 / Float64(t_2 + Float64(Float64(Float64(1.0 - t_2) / t_1) * Float64(t_2 + Float64(1.0 - t_0)))))));
	end
	return tmp
end
function tmp = code(p, x)
	tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
end
function tmp_2 = code(p, x)
	t_0 = x / hypot(x, (p * 2.0));
	t_1 = 1.0 + (t_0 ^ 3.0);
	t_2 = t_0 ^ 2.0;
	tmp = 0.0;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0)
		tmp = (sqrt((p * (p * 6.0))) * (-sqrt(0.5) / x)) / sqrt((1.0 + (t_2 - t_0)));
	else
		tmp = sqrt((0.5 * (t_1 / (t_2 + (((1.0 - t_2) / t_1) * (t_2 + (1.0 - t_0)))))));
	end
	tmp_2 = tmp;
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]
code[p_, x_] := Block[{t$95$0 = N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$0, 2.0], $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(N[Sqrt[N[(p * N[(p * 6.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[0.5], $MachinePrecision]) / x), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 + N[(t$95$2 - t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(t$95$1 / N[(t$95$2 + N[(N[(N[(1.0 - t$95$2), $MachinePrecision] / t$95$1), $MachinePrecision] * N[(t$95$2 + N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\begin{array}{l}
t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\
t_1 := 1 + {t_0}^{3}\\
t_2 := {t_0}^{2}\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\frac{\sqrt{p \cdot \left(p \cdot 6\right)} \cdot \frac{-\sqrt{0.5}}{x}}{\sqrt{1 + \left(t_2 - t_0\right)}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{t_1}{t_2 + \frac{1 - t_2}{t_1} \cdot \left(t_2 + \left(1 - t_0\right)\right)}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.1
Target13.1
Herbie6.0
\[\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1

    1. Initial program 53.6

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Applied egg-rr53.6

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

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

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

      [Start]24.2

      \[ \frac{-1 \cdot \left(\frac{\sqrt{0.5}}{x} \cdot \sqrt{2 \cdot {p}^{2} + 4 \cdot {p}^{2}}\right)}{\sqrt{1 + \left({\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{2} - \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}} \]

      associate-*r* [=>]24.2

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

      *-commutative [=>]24.2

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

      distribute-rgt-out [=>]24.2

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

      unpow2 [=>]24.2

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

      metadata-eval [=>]24.2

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

      associate-*l* [=>]24.1

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

      mul-1-neg [=>]24.1

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

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

    1. Initial program 0.3

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Applied egg-rr0.3

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

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

      [Start]0.3

      \[ \sqrt{0.5 \cdot \left(\left(1 + {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{3}\right) \cdot \frac{1}{1 + \left({\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{2} - \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}\right)} \]

      associate-*r/ [=>]0.3

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

      *-rgt-identity [=>]0.3

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

      associate-+r- [=>]0.3

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

      +-commutative [=>]0.3

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

      associate--l+ [=>]0.3

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

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

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

      [Start]0.3

      \[ \sqrt{0.5 \cdot \frac{1 + {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{3}}{{\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{2} + \frac{1 - {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{2}}{1 + {\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{3}} \cdot \left(1 + \left({\left(\frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)}^{2} - \frac{x}{\mathsf{hypot}\left(x, 2 \cdot p\right)}\right)\right)}} \]

      *-commutative [=>]0.3

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

      *-commutative [=>]0.3

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

      associate-+r- [=>]0.3

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

      +-commutative [=>]0.3

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

      associate--l+ [=>]0.3

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

      *-commutative [=>]0.3

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

      *-commutative [=>]0.3

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

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

Alternatives

Alternative 1
Error6.0
Cost47364
\[\begin{array}{l} t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\ t_1 := {t_0}^{2}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{\sqrt{p \cdot \left(p \cdot 6\right)} \cdot \frac{-\sqrt{0.5}}{x}}{\sqrt{1 + \left(t_1 - t_0\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{3}}{t_1 + \left(1 - t_0\right)}}\\ \end{array} \]
Alternative 2
Error6.0
Cost47300
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, p \cdot 2\right)\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{\sqrt{p \cdot \left(p \cdot 6\right)} \cdot \frac{-\sqrt{0.5}}{x}}{\sqrt{1 + \left({t_1}^{2} - t_1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{t_0}}\\ \end{array} \]
Alternative 3
Error6.0
Cost20612
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\ \;\;\;\;\frac{-\sqrt{2}}{\frac{x}{\sqrt{0.5 \cdot \left(p \cdot p\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \end{array} \]
Alternative 4
Error13.5
Cost13705
\[\begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+14} \lor \neg \left(x \leq -8000000000\right):\\ \;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-p}{x}\\ \end{array} \]
Alternative 5
Error20.0
Cost6860
\[\begin{array}{l} \mathbf{if}\;p \leq -1.85 \cdot 10^{-36}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 2.15 \cdot 10^{-266}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 6.8 \cdot 10^{-74}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 6
Error35.6
Cost388
\[\begin{array}{l} \mathbf{if}\;x \leq -1.38 \cdot 10^{-132}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error40.9
Cost64
\[1 \]

Error

Reproduce?

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

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

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