Given's Rotation SVD example

Percentage Accurate: 78.9% → 78.9%
Time: 3.5s
Alternatives: 8
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 8 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: 78.9% 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: 78.9% 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}
Derivation
  1. Initial program 79.0%

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 39.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\\ \mathbf{if}\;t\_0 \leq 0.004:\\ \;\;\;\;1 + t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))
   (if (<= t_0 0.004) (+ 1.0 t_0) t_0)))
double code(double p, double x) {
	double t_0 = x / sqrt((((4.0 * p) * p) + (x * x)));
	double tmp;
	if (t_0 <= 0.004) {
		tmp = 1.0 + t_0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x / sqrt((((4.0d0 * p) * p) + (x * x)))
    if (t_0 <= 0.004d0) then
        tmp = 1.0d0 + t_0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double t_0 = x / Math.sqrt((((4.0 * p) * p) + (x * x)));
	double tmp;
	if (t_0 <= 0.004) {
		tmp = 1.0 + t_0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(p, x):
	t_0 = x / math.sqrt((((4.0 * p) * p) + (x * x)))
	tmp = 0
	if t_0 <= 0.004:
		tmp = 1.0 + t_0
	else:
		tmp = t_0
	return tmp
function code(p, x)
	t_0 = Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))
	tmp = 0.0
	if (t_0 <= 0.004)
		tmp = Float64(1.0 + t_0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(p, x)
	t_0 = x / sqrt((((4.0 * p) * p) + (x * x)));
	tmp = 0.0;
	if (t_0 <= 0.004)
		tmp = 1.0 + t_0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[p_, x_] := Block[{t$95$0 = N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.004], N[(1.0 + t$95$0), $MachinePrecision], t$95$0]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\\
\mathbf{if}\;t\_0 \leq 0.004:\\
\;\;\;\;1 + t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 72.5%

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

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

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

    if 0.0040000000000000001 < (/.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. Add Preprocessing
    3. Taylor expanded in p around 0

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

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

Alternative 3: 31.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := \left(4 \cdot p\right) \cdot p\\
t_1 := \frac{x}{\sqrt{t\_0 + x \cdot x}}\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{-143}:\\
\;\;\;\;0.5 \cdot t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\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)))) < 5.0000000000000002e-143

    1. Initial program 69.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. Taylor expanded in p around 0

      \[\leadsto \color{blue}{-1 \cdot \frac{{p}^{2} \cdot \sqrt{\frac{1}{2}}}{{x}^{2} \cdot \sqrt{2}} + \sqrt{\frac{1}{2}} \cdot \sqrt{2}} \]
    4. Applied rewrites19.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    5. Taylor expanded in p around 0

      \[\leadsto \frac{1}{2} \cdot \left(2 + \color{blue}{{p}^{2} \cdot \left(6 \cdot \frac{{p}^{2}}{{x}^{4}} - 2 \cdot \frac{1}{{x}^{2}}\right)}\right) \]
    6. Applied rewrites4.0%

      \[\leadsto 0.5 \cdot \left(4 \cdot \color{blue}{p}\right) \]
    7. Taylor expanded in p around 0

      \[\leadsto \frac{1}{2} \cdot \left(4 \cdot p\right) \]
    8. Applied rewrites9.9%

      \[\leadsto 0.5 \cdot \left(\left(4 \cdot p\right) \cdot p\right) \]

    if 5.0000000000000002e-143 < (/.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. Add Preprocessing
    3. Taylor expanded in p around 0

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

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

Alternative 4: 39.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ 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
 (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))))))
double code(double p, double x) {
	return 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 = 0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))
end function
public static double code(double p, double x) {
	return 0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))));
}
def code(p, x):
	return 0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))
function code(p, x)
	return 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 = 0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))));
end
code[p_, x_] := 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]
\begin{array}{l}

\\
0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)
\end{array}
Derivation
  1. Initial program 79.0%

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

    \[\leadsto \color{blue}{-1 \cdot \frac{{p}^{2} \cdot \sqrt{\frac{1}{2}}}{{x}^{2} \cdot \sqrt{2}} + \sqrt{\frac{1}{2}} \cdot \sqrt{2}} \]
  4. Applied rewrites38.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  5. Add Preprocessing

Alternative 5: 9.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(4 \cdot p\right) \cdot p\\ \mathbf{if}\;x \leq -2.6 \cdot 10^{+25}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\sqrt{t\_0 + x \cdot x}}\\ \end{array} \end{array} \]
(FPCore (p x)
 :precision binary64
 (let* ((t_0 (* (* 4.0 p) p)))
   (if (<= x -2.6e+25) t_0 (sqrt (sqrt (+ t_0 (* x x)))))))
double code(double p, double x) {
	double t_0 = (4.0 * p) * p;
	double tmp;
	if (x <= -2.6e+25) {
		tmp = t_0;
	} else {
		tmp = sqrt(sqrt((t_0 + (x * x))));
	}
	return tmp;
}
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (4.0d0 * p) * p
    if (x <= (-2.6d+25)) then
        tmp = t_0
    else
        tmp = sqrt(sqrt((t_0 + (x * x))))
    end if
    code = tmp
end function
public static double code(double p, double x) {
	double t_0 = (4.0 * p) * p;
	double tmp;
	if (x <= -2.6e+25) {
		tmp = t_0;
	} else {
		tmp = Math.sqrt(Math.sqrt((t_0 + (x * x))));
	}
	return tmp;
}
def code(p, x):
	t_0 = (4.0 * p) * p
	tmp = 0
	if x <= -2.6e+25:
		tmp = t_0
	else:
		tmp = math.sqrt(math.sqrt((t_0 + (x * x))))
	return tmp
function code(p, x)
	t_0 = Float64(Float64(4.0 * p) * p)
	tmp = 0.0
	if (x <= -2.6e+25)
		tmp = t_0;
	else
		tmp = sqrt(sqrt(Float64(t_0 + Float64(x * x))));
	end
	return tmp
end
function tmp_2 = code(p, x)
	t_0 = (4.0 * p) * p;
	tmp = 0.0;
	if (x <= -2.6e+25)
		tmp = t_0;
	else
		tmp = sqrt(sqrt((t_0 + (x * x))));
	end
	tmp_2 = tmp;
end
code[p_, x_] := Block[{t$95$0 = N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision]}, If[LessEqual[x, -2.6e+25], t$95$0, N[Sqrt[N[Sqrt[N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(4 \cdot p\right) \cdot p\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{+25}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{t\_0 + x \cdot x}}\\


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

    1. Initial program 47.6%

      \[\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 p around 0

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

      \[\leadsto \color{blue}{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \]
    5. Taylor expanded in p around 0

      \[\leadsto 2 + \color{blue}{{p}^{2} \cdot \left(6 \cdot \frac{{p}^{2}}{{x}^{4}} - 2 \cdot \frac{1}{{x}^{2}}\right)} \]
    6. Applied rewrites4.7%

      \[\leadsto 4 \cdot \color{blue}{p} \]
    7. Taylor expanded in p around 0

      \[\leadsto 4 \cdot p \]
    8. Applied rewrites23.5%

      \[\leadsto \left(4 \cdot p\right) \cdot p \]

    if -2.5999999999999998e25 < x

    1. Initial program 86.6%

      \[\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 p around 0

      \[\leadsto \sqrt{\color{blue}{1}} \]
    4. Applied rewrites6.9%

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

Alternative 6: 7.8% accurate, 3.6× speedup?

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

\\
0.5 \cdot \left(\left(4 \cdot p\right) \cdot p\right)
\end{array}
Derivation
  1. Initial program 79.0%

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

    \[\leadsto \color{blue}{-1 \cdot \frac{{p}^{2} \cdot \sqrt{\frac{1}{2}}}{{x}^{2} \cdot \sqrt{2}} + \sqrt{\frac{1}{2}} \cdot \sqrt{2}} \]
  4. Applied rewrites38.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
  5. Taylor expanded in p around 0

    \[\leadsto \frac{1}{2} \cdot \left(2 + \color{blue}{{p}^{2} \cdot \left(6 \cdot \frac{{p}^{2}}{{x}^{4}} - 2 \cdot \frac{1}{{x}^{2}}\right)}\right) \]
  6. Applied rewrites3.9%

    \[\leadsto 0.5 \cdot \left(4 \cdot \color{blue}{p}\right) \]
  7. Taylor expanded in p around 0

    \[\leadsto \frac{1}{2} \cdot \left(4 \cdot p\right) \]
  8. Applied rewrites8.2%

    \[\leadsto 0.5 \cdot \left(\left(4 \cdot p\right) \cdot p\right) \]
  9. Add Preprocessing

Alternative 7: 7.8% accurate, 5.3× speedup?

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

\\
\left(4 \cdot p\right) \cdot p
\end{array}
Derivation
  1. Initial program 79.0%

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

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

    \[\leadsto \color{blue}{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \]
  5. Taylor expanded in p around 0

    \[\leadsto 2 + \color{blue}{{p}^{2} \cdot \left(6 \cdot \frac{{p}^{2}}{{x}^{4}} - 2 \cdot \frac{1}{{x}^{2}}\right)} \]
  6. Applied rewrites3.9%

    \[\leadsto 4 \cdot \color{blue}{p} \]
  7. Taylor expanded in p around 0

    \[\leadsto 4 \cdot p \]
  8. Applied rewrites8.2%

    \[\leadsto \left(4 \cdot p\right) \cdot p \]
  9. Add Preprocessing

Alternative 8: 4.0% accurate, 9.7× speedup?

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

\\
4 \cdot p
\end{array}
Derivation
  1. Initial program 79.0%

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

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

    \[\leadsto \color{blue}{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \]
  5. Taylor expanded in p around 0

    \[\leadsto 2 + \color{blue}{{p}^{2} \cdot \left(6 \cdot \frac{{p}^{2}}{{x}^{4}} - 2 \cdot \frac{1}{{x}^{2}}\right)} \]
  6. Applied rewrites3.9%

    \[\leadsto 4 \cdot \color{blue}{p} \]
  7. Add Preprocessing

Developer Target 1: 78.9% accurate, 0.2× 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 2024321 
(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))))))))