?

Average Accuracy: 79.0% → 55.4%
Time: 10.2s
Precision: binary64
Cost: 7124

?

\[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} \mathbf{if}\;p \leq 4.4 \cdot 10^{-10}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 1.35 \cdot 10^{-203}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 7.2 \cdot 10^{-255}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 8 \cdot 10^{-284}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 3.3 \cdot 10^{-106}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \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
 (if (<= p 4.4e-10)
   (sqrt 0.5)
   (if (<= p 1.35e-203)
     1.0
     (if (<= p 7.2e-255)
       (/ p x)
       (if (<= p 8e-284) 1.0 (if (<= p 3.3e-106) (/ (- p) x) (sqrt 0.5)))))))
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 tmp;
	if (p <= 4.4e-10) {
		tmp = sqrt(0.5);
	} else if (p <= 1.35e-203) {
		tmp = 1.0;
	} else if (p <= 7.2e-255) {
		tmp = p / x;
	} else if (p <= 8e-284) {
		tmp = 1.0;
	} else if (p <= 3.3e-106) {
		tmp = -p / x;
	} else {
		tmp = sqrt(0.5);
	}
	return tmp;
}
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
real(8) function code(p, x)
    real(8), intent (in) :: p
    real(8), intent (in) :: x
    real(8) :: tmp
    if (p <= 4.4d-10) then
        tmp = sqrt(0.5d0)
    else if (p <= 1.35d-203) then
        tmp = 1.0d0
    else if (p <= 7.2d-255) then
        tmp = p / x
    else if (p <= 8d-284) then
        tmp = 1.0d0
    else if (p <= 3.3d-106) then
        tmp = -p / x
    else
        tmp = sqrt(0.5d0)
    end if
    code = tmp
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)))))));
}
public static double code(double p, double x) {
	double tmp;
	if (p <= 4.4e-10) {
		tmp = Math.sqrt(0.5);
	} else if (p <= 1.35e-203) {
		tmp = 1.0;
	} else if (p <= 7.2e-255) {
		tmp = p / x;
	} else if (p <= 8e-284) {
		tmp = 1.0;
	} else if (p <= 3.3e-106) {
		tmp = -p / x;
	} else {
		tmp = Math.sqrt(0.5);
	}
	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):
	tmp = 0
	if p <= 4.4e-10:
		tmp = math.sqrt(0.5)
	elif p <= 1.35e-203:
		tmp = 1.0
	elif p <= 7.2e-255:
		tmp = p / x
	elif p <= 8e-284:
		tmp = 1.0
	elif p <= 3.3e-106:
		tmp = -p / x
	else:
		tmp = math.sqrt(0.5)
	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)
	tmp = 0.0
	if (p <= 4.4e-10)
		tmp = sqrt(0.5);
	elseif (p <= 1.35e-203)
		tmp = 1.0;
	elseif (p <= 7.2e-255)
		tmp = Float64(p / x);
	elseif (p <= 8e-284)
		tmp = 1.0;
	elseif (p <= 3.3e-106)
		tmp = Float64(Float64(-p) / x);
	else
		tmp = sqrt(0.5);
	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)
	tmp = 0.0;
	if (p <= 4.4e-10)
		tmp = sqrt(0.5);
	elseif (p <= 1.35e-203)
		tmp = 1.0;
	elseif (p <= 7.2e-255)
		tmp = p / x;
	elseif (p <= 8e-284)
		tmp = 1.0;
	elseif (p <= 3.3e-106)
		tmp = -p / x;
	else
		tmp = sqrt(0.5);
	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_] := If[LessEqual[p, 4.4e-10], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 1.35e-203], 1.0, If[LessEqual[p, 7.2e-255], N[(p / x), $MachinePrecision], If[LessEqual[p, 8e-284], 1.0, If[LessEqual[p, 3.3e-106], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]]]]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\begin{array}{l}
\mathbf{if}\;p \leq 4.4 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{0.5}\\

\mathbf{elif}\;p \leq 1.35 \cdot 10^{-203}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 7.2 \cdot 10^{-255}:\\
\;\;\;\;\frac{p}{x}\\

\mathbf{elif}\;p \leq 8 \cdot 10^{-284}:\\
\;\;\;\;1\\

\mathbf{elif}\;p \leq 3.3 \cdot 10^{-106}:\\
\;\;\;\;\frac{-p}{x}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original79.0%
Target79.0%
Herbie55.4%
\[\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 4 regimes
  2. if p < 4.3999999999999998e-10 or 3.30000000000000016e-106 < p

    1. Initial program 80.7%

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

      \[\leadsto \color{blue}{\sqrt{0.5}} \]

    if 4.3999999999999998e-10 < p < 1.34999999999999999e-203 or 7.2000000000000004e-255 < p < 8.00000000000000029e-284

    1. Initial program 80.7%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Taylor expanded in x around inf 34.4%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{2}} \]

    if 1.34999999999999999e-203 < p < 7.2000000000000004e-255

    1. Initial program 80.7%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Taylor expanded in x around -inf 18.2%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}} \]
    3. Simplified21.5%

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

      [Start]18.2

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

      unpow2 [=>]18.2

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

      unpow2 [=>]18.2

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

      times-frac [=>]21.5

      \[ \sqrt{0.5 \cdot \left(2 \cdot \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)}\right)} \]
    4. Taylor expanded in p around 0 15.7%

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

    if 8.00000000000000029e-284 < p < 3.30000000000000016e-106

    1. Initial program 80.7%

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)} \]
    2. Taylor expanded in x around -inf 18.2%

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}} \]
    3. Simplified21.5%

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

      [Start]18.2

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

      unpow2 [=>]18.2

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

      unpow2 [=>]18.2

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

      times-frac [=>]21.5

      \[ \sqrt{0.5 \cdot \left(2 \cdot \color{blue}{\left(\frac{p}{x} \cdot \frac{p}{x}\right)}\right)} \]
    4. Taylor expanded in p around -inf 17.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{p}{x}} \]
    5. Simplified17.8%

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

      [Start]17.8

      \[ -1 \cdot \frac{p}{x} \]

      associate-*r/ [=>]17.8

      \[ \color{blue}{\frac{-1 \cdot p}{x}} \]

      neg-mul-1 [<=]17.8

      \[ \frac{\color{blue}{-p}}{x} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification57.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;p \leq 4.4 \cdot 10^{-10}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 1.35 \cdot 10^{-203}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 7.2 \cdot 10^{-255}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 8 \cdot 10^{-284}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 3.3 \cdot 10^{-106}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy43.0%
Cost27140
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq 0.05:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left({\left(0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, p + p\right)}{x}}\right)}^{1.5}\right)}^{0.3333333333333333}\\ \end{array} \]
Alternative 2
Accuracy43.0%
Cost20612
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq 0.05:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}\\ \end{array} \]
Alternative 3
Accuracy51.2%
Cost7124
\[\begin{array}{l} \mathbf{if}\;p \leq 5.2 \cdot 10^{-9}:\\ \;\;\;\;\sqrt{0.5 \cdot \left(1 + -0.5 \cdot \frac{x}{p}\right)}\\ \mathbf{elif}\;p \leq 1.25 \cdot 10^{-203}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 10^{-257}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 5.6 \cdot 10^{-284}:\\ \;\;\;\;1\\ \mathbf{elif}\;p \leq 3.4 \cdot 10^{-106}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 4
Accuracy55.4%
Cost6860
\[\begin{array}{l} \mathbf{if}\;p \leq 3 \cdot 10^{-44}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;p \leq 3.2 \cdot 10^{-302}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{elif}\;p \leq 3 \cdot 10^{-106}:\\ \;\;\;\;\frac{-p}{x}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5}\\ \end{array} \]
Alternative 5
Accuracy26.9%
Cost388
\[\begin{array}{l} \mathbf{if}\;p \leq 3.2 \cdot 10^{-302}:\\ \;\;\;\;\frac{p}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-p}{x}\\ \end{array} \]
Alternative 6
Accuracy16.9%
Cost192
\[\frac{p}{x} \]

Error

Reproduce?

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