Given's Rotation SVD example

?

Percentage Accurate: 79.5% → 99.9%
Time: 11.7s
Precision: binary64
Cost: 52996

?

\[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 := \sqrt[3]{\frac{x}{\mathsf{hypot}\left(x, p + p\right)}}\\ \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.99999998:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left({t_0}^{2}, t_0, 1\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 (cbrt (/ x (hypot x (+ p p))))))
   (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.99999998)
     (fabs (/ p x))
     (sqrt (* 0.5 (fma (pow t_0 2.0) t_0 1.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 = cbrt((x / hypot(x, (p + p))));
	double tmp;
	if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.99999998) {
		tmp = fabs((p / x));
	} else {
		tmp = sqrt((0.5 * fma(pow(t_0, 2.0), t_0, 1.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 = cbrt(Float64(x / hypot(x, Float64(p + p))))
	tmp = 0.0
	if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.99999998)
		tmp = abs(Float64(p / x));
	else
		tmp = sqrt(Float64(0.5 * fma((t_0 ^ 2.0), t_0, 1.0)));
	end
	return 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[Power[N[(x / N[Sqrt[x ^ 2 + N[(p + p), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.99999998], N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Power[t$95$0, 2.0], $MachinePrecision] * t$95$0 + 1.0), $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 := \sqrt[3]{\frac{x}{\mathsf{hypot}\left(x, p + p\right)}}\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.99999998:\\
\;\;\;\;\left|\frac{p}{x}\right|\\

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


\end{array}

Local Percentage Accuracy?

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.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Target

Original79.5%
Target79.5%
Herbie99.9%
\[\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)))) < -0.999999980000000011

    1. Initial program 11.5%

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

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

      [Start]11.5

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

      add-exp-log [=>]11.5

      \[ \sqrt{0.5 \cdot \color{blue}{e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]

      log1p-udef [<=]11.5

      \[ \sqrt{0.5 \cdot e^{\color{blue}{\mathsf{log1p}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]

      +-commutative [=>]11.5

      \[ \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{\color{blue}{x \cdot x + \left(4 \cdot p\right) \cdot p}}}\right)}} \]

      add-sqr-sqrt [=>]11.5

      \[ \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)}} \]

      hypot-def [=>]11.5

      \[ \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)}} \]

      associate-*l* [=>]11.5

      \[ \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)}} \]

      sqrt-prod [=>]11.5

      \[ \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\sqrt{4} \cdot \sqrt{p \cdot p}}\right)}\right)}} \]

      metadata-eval [=>]11.5

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

      sqrt-unprod [<=]6.8

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

      add-sqr-sqrt [<=]11.5

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

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

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

      [Start]46.6

      \[ \sqrt{0.5} \cdot \sqrt{e^{2 \cdot \log \left(\frac{-1}{x}\right) + \log \left(--2 \cdot {p}^{2}\right)}} \]

      exp-sum [=>]46.7

      \[ \sqrt{0.5} \cdot \sqrt{\color{blue}{e^{2 \cdot \log \left(\frac{-1}{x}\right)} \cdot e^{\log \left(--2 \cdot {p}^{2}\right)}}} \]

      *-commutative [=>]46.7

      \[ \sqrt{0.5} \cdot \sqrt{e^{\color{blue}{\log \left(\frac{-1}{x}\right) \cdot 2}} \cdot e^{\log \left(--2 \cdot {p}^{2}\right)}} \]

      exp-to-pow [=>]46.9

      \[ \sqrt{0.5} \cdot \sqrt{\color{blue}{{\left(\frac{-1}{x}\right)}^{2}} \cdot e^{\log \left(--2 \cdot {p}^{2}\right)}} \]

      rem-exp-log [=>]49.4

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

      distribute-lft-neg-in [=>]49.4

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

      metadata-eval [=>]49.4

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

      unpow2 [=>]49.4

      \[ \sqrt{0.5} \cdot \sqrt{{\left(\frac{-1}{x}\right)}^{2} \cdot \left(2 \cdot \color{blue}{\left(p \cdot p\right)}\right)} \]
    5. Applied egg-rr46.2%

      \[\leadsto \color{blue}{{\left({\left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3}} \]
      Step-by-step derivation

      [Start]49.4

      \[ \sqrt{0.5} \cdot \sqrt{{\left(\frac{-1}{x}\right)}^{2} \cdot \left(2 \cdot \left(p \cdot p\right)\right)} \]

      add-cube-cbrt [=>]49.0

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

      pow3 [=>]49.0

      \[ \color{blue}{{\left(\sqrt[3]{\sqrt{0.5} \cdot \sqrt{{\left(\frac{-1}{x}\right)}^{2} \cdot \left(2 \cdot \left(p \cdot p\right)\right)}}\right)}^{3}} \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\left|\frac{p}{x}\right|} \]
      Step-by-step derivation

      [Start]46.2

      \[ {\left({\left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}^{0.16666666666666666}\right)}^{3} \]

      exp-to-pow [<=]46.2

      \[ \color{blue}{e^{\log \left({\left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}^{0.16666666666666666}\right) \cdot 3}} \]

      *-commutative [=>]46.2

      \[ e^{\color{blue}{3 \cdot \log \left({\left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}^{0.16666666666666666}\right)}} \]

      log-pow [=>]46.4

      \[ e^{3 \cdot \color{blue}{\left(0.16666666666666666 \cdot \log \left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)\right)}} \]

      associate-*r* [=>]46.8

      \[ e^{\color{blue}{\left(3 \cdot 0.16666666666666666\right) \cdot \log \left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}} \]

      metadata-eval [=>]46.8

      \[ e^{\color{blue}{0.5} \cdot \log \left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)} \]

      *-commutative [<=]46.8

      \[ e^{\color{blue}{\log \left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right) \cdot 0.5}} \]

      exp-to-pow [=>]49.5

      \[ \color{blue}{{\left(\left(2 \cdot \left(\left(p \cdot p\right) \cdot {x}^{-2}\right)\right) \cdot 0.5\right)}^{0.5}} \]

      unpow1/2 [=>]49.5

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

      *-commutative [=>]49.5

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

      associate-*l* [=>]49.5

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

      unpow2 [<=]49.5

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

      metadata-eval [=>]49.5

      \[ \sqrt{\left({p}^{2} \cdot {x}^{-2}\right) \cdot \color{blue}{1}} \]

      associate-*r* [<=]49.5

      \[ \sqrt{\color{blue}{{p}^{2} \cdot \left({x}^{-2} \cdot 1\right)}} \]

      unpow2 [=>]49.5

      \[ \sqrt{\color{blue}{\left(p \cdot p\right)} \cdot \left({x}^{-2} \cdot 1\right)} \]

      *-rgt-identity [=>]49.5

      \[ \sqrt{\left(p \cdot p\right) \cdot \color{blue}{{x}^{-2}}} \]

      metadata-eval [<=]49.5

      \[ \sqrt{\left(p \cdot p\right) \cdot {x}^{\color{blue}{\left(2 \cdot -1\right)}}} \]

      pow-sqr [<=]49.3

      \[ \sqrt{\left(p \cdot p\right) \cdot \color{blue}{\left({x}^{-1} \cdot {x}^{-1}\right)}} \]

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

    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. Applied egg-rr99.8%

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

      [Start]99.8

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

      add-exp-log [=>]99.8

      \[ \sqrt{0.5 \cdot \color{blue}{e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]

      log1p-udef [<=]99.8

      \[ \sqrt{0.5 \cdot e^{\color{blue}{\mathsf{log1p}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \]

      +-commutative [=>]99.8

      \[ \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\sqrt{\color{blue}{x \cdot x + \left(4 \cdot p\right) \cdot p}}}\right)}} \]

      add-sqr-sqrt [=>]99.8

      \[ \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)}} \]

      hypot-def [=>]99.8

      \[ \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)}} \]

      associate-*l* [=>]99.8

      \[ \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)}} \]

      sqrt-prod [=>]99.8

      \[ \sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, \color{blue}{\sqrt{4} \cdot \sqrt{p \cdot p}}\right)}\right)}} \]

      metadata-eval [=>]99.8

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

      sqrt-unprod [<=]48.5

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

      add-sqr-sqrt [<=]99.8

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

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

      [Start]99.8

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

      log1p-udef [=>]99.8

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

      add-exp-log [<=]99.8

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

      +-commutative [=>]99.8

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

      add-cube-cbrt [=>]99.8

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

      fma-def [=>]99.8

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

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

Alternatives

Alternative 1
Accuracy99.9%
Cost33284
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.99999998:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot e^{\mathsf{log1p}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}}\\ \end{array} \]
Alternative 2
Accuracy99.9%
Cost20612
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.99999998:\\ \;\;\;\;\left|\frac{p}{x}\right|\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\ \end{array} \]
Alternative 3
Accuracy69.2%
Cost7256
\[\begin{array}{l} t_0 := \left|\frac{p}{x}\right|\\ \mathbf{if}\;p \leq -2.6 \cdot 10^{-59}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq -1 \cdot 10^{-266}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 7.5 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 9.8 \cdot 10^{-189}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 8 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 6.2 \cdot 10^{-5}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 4
Accuracy69.0%
Cost7256
\[\begin{array}{l} t_0 := \left|\frac{p}{x}\right|\\ \mathbf{if}\;p \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;\sqrt{0.5 + -0.25 \cdot \frac{x}{p}}\\ \mathbf{elif}\;p \leq -1.9 \cdot 10^{-266}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 4.8 \cdot 10^{-248}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 2.8 \cdot 10^{-189}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 2.9 \cdot 10^{-135}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;p \leq 5.2 \cdot 10^{-6}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 5
Accuracy68.8%
Cost6992
\[\begin{array}{l} \mathbf{if}\;p \leq -8.5 \cdot 10^{-59}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 1.55 \cdot 10^{-189}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 9.6 \cdot 10^{-144}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{elif}\;p \leq 5.2 \cdot 10^{-6}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 6
Accuracy43.7%
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{-46}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Accuracy36.1%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023160 
(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))))))))