
(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:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.5) (sqrt (+ (pow (/ x p) -2.0) (* 0.5 (* -6.0 (pow (/ p x) 4.0))))) (sqrt (* 0.5 (+ 1.0 (+ 1.0 (+ (/ x (hypot (* p 2.0) x)) -1.0)))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
tmp = sqrt((pow((x / p), -2.0) + (0.5 * (-6.0 * pow((p / x), 4.0)))));
} else {
tmp = sqrt((0.5 * (1.0 + (1.0 + ((x / hypot((p * 2.0), x)) + -1.0)))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
tmp = Math.sqrt((Math.pow((x / p), -2.0) + (0.5 * (-6.0 * Math.pow((p / x), 4.0)))));
} else {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 + ((x / Math.hypot((p * 2.0), x)) + -1.0)))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5: tmp = math.sqrt((math.pow((x / p), -2.0) + (0.5 * (-6.0 * math.pow((p / x), 4.0))))) else: tmp = math.sqrt((0.5 * (1.0 + (1.0 + ((x / math.hypot((p * 2.0), x)) + -1.0))))) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.5) tmp = sqrt(Float64((Float64(x / p) ^ -2.0) + Float64(0.5 * Float64(-6.0 * (Float64(p / x) ^ 4.0))))); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 + Float64(Float64(x / hypot(Float64(p * 2.0), x)) + -1.0))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) tmp = sqrt((((x / p) ^ -2.0) + (0.5 * (-6.0 * ((p / x) ^ 4.0))))); else tmp = sqrt((0.5 * (1.0 + (1.0 + ((x / hypot((p * 2.0), x)) + -1.0))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], N[Sqrt[N[(N[Power[N[(x / p), $MachinePrecision], -2.0], $MachinePrecision] + N[(0.5 * N[(-6.0 * N[Power[N[(p / x), $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 + N[(N[(x / N[Sqrt[N[(p * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.5:\\
\;\;\;\;\sqrt{{\left(\frac{x}{p}\right)}^{-2} + 0.5 \cdot \left(-6 \cdot {\left(\frac{p}{x}\right)}^{4}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \left(1 + \left(\frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)} + -1\right)\right)\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.5Initial program 13.1%
add-sqr-sqrt13.1%
hypot-def13.2%
associate-*l*13.2%
sqrt-prod13.2%
metadata-eval13.2%
sqrt-unprod8.5%
add-sqr-sqrt13.2%
Applied egg-rr13.2%
Taylor expanded in x around -inf 39.7%
fma-def39.7%
unpow239.7%
unpow239.7%
distribute-rgt-out39.7%
metadata-eval39.7%
Simplified39.7%
expm1-log1p-u39.7%
expm1-udef12.7%
Applied egg-rr16.4%
expm1-def66.4%
expm1-log1p66.4%
fma-udef66.4%
unpow266.4%
times-frac53.3%
unpow253.3%
unpow253.3%
distribute-lft-in53.3%
Simplified66.1%
if -0.5 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
add-sqr-sqrt100.0%
hypot-def100.0%
associate-*l*100.0%
sqrt-prod100.0%
metadata-eval100.0%
sqrt-unprod46.9%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
log1p-udef100.0%
add-exp-log100.0%
Applied egg-rr100.0%
associate--l+100.0%
*-commutative100.0%
Simplified100.0%
Final simplification94.0%
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999996) (sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x))))) (sqrt (* 0.5 (fma (/ 1.0 (hypot x (* p 2.0))) x 1.0)))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999996) {
tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = sqrt((0.5 * fma((1.0 / hypot(x, (p * 2.0))), x, 1.0)));
}
return tmp;
}
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.9999996) tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x))))); else tmp = sqrt(Float64(0.5 * fma(Float64(1.0 / hypot(x, Float64(p * 2.0))), x, 1.0))); end return tmp end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.9999996], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999996:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(x, p \cdot 2\right)}, x, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99999959999999999Initial program 11.8%
Taylor expanded in x around -inf 52.7%
unpow252.7%
unpow252.7%
times-frac66.0%
Simplified66.0%
if -0.99999959999999999 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
+-commutative99.8%
clear-num99.8%
associate-/r/99.8%
fma-def99.8%
+-commutative99.8%
add-sqr-sqrt99.8%
hypot-def99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod47.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification94.0%
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999996) (sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x))))) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999996) {
tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999996) {
tmp = Math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999996: tmp = math.sqrt((0.5 * (2.0 * ((p / x) * (p / x))))) else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x))))) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.9999996) tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x))))); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999996) tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x))))); else tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.9999996], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999996:\\
\;\;\;\;\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}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99999959999999999Initial program 11.8%
Taylor expanded in x around -inf 52.7%
unpow252.7%
unpow252.7%
times-frac66.0%
Simplified66.0%
if -0.99999959999999999 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
add-sqr-sqrt99.8%
hypot-def99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod47.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification94.0%
(FPCore (p x) :precision binary64 (if (<= p -5.8e-65) (sqrt 0.5) (if (<= p -8e-221) (/ p x) (if (<= p 1.5e-74) (/ (- p) x) (sqrt 0.5)))))
double code(double p, double x) {
double tmp;
if (p <= -5.8e-65) {
tmp = sqrt(0.5);
} else if (p <= -8e-221) {
tmp = p / x;
} else if (p <= 1.5e-74) {
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
real(8) :: tmp
if (p <= (-5.8d-65)) then
tmp = sqrt(0.5d0)
else if (p <= (-8d-221)) then
tmp = p / x
else if (p <= 1.5d-74) then
tmp = -p / x
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= -5.8e-65) {
tmp = Math.sqrt(0.5);
} else if (p <= -8e-221) {
tmp = p / x;
} else if (p <= 1.5e-74) {
tmp = -p / x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -5.8e-65: tmp = math.sqrt(0.5) elif p <= -8e-221: tmp = p / x elif p <= 1.5e-74: tmp = -p / x else: tmp = math.sqrt(0.5) return tmp
function code(p, x) tmp = 0.0 if (p <= -5.8e-65) tmp = sqrt(0.5); elseif (p <= -8e-221) tmp = Float64(p / x); elseif (p <= 1.5e-74) tmp = Float64(Float64(-p) / x); else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -5.8e-65) tmp = sqrt(0.5); elseif (p <= -8e-221) tmp = p / x; elseif (p <= 1.5e-74) tmp = -p / x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -5.8e-65], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, -8e-221], N[(p / x), $MachinePrecision], If[LessEqual[p, 1.5e-74], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -5.8 \cdot 10^{-65}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq -8 \cdot 10^{-221}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{elif}\;p \leq 1.5 \cdot 10^{-74}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < -5.7999999999999996e-65 or 1.50000000000000003e-74 < p Initial program 92.0%
Taylor expanded in x around 0 78.1%
if -5.7999999999999996e-65 < p < -8.00000000000000014e-221Initial program 59.1%
Taylor expanded in x around -inf 9.9%
unpow29.9%
unpow29.9%
times-frac18.5%
Simplified18.5%
Taylor expanded in p around 0 45.0%
if -8.00000000000000014e-221 < p < 1.50000000000000003e-74Initial program 70.3%
log1p-expm1-u70.3%
log1p-udef70.3%
+-commutative70.3%
distribute-rgt-in70.3%
metadata-eval70.3%
fma-def70.3%
Applied egg-rr70.3%
Taylor expanded in x around -inf 39.2%
associate-*r/39.2%
mul-1-neg39.2%
Simplified39.2%
Final simplification67.3%
(FPCore (p x) :precision binary64 (if (<= p -1.25e-42) (sqrt 0.5) (if (<= p 4300000000000.0) 1.0 (sqrt 0.5))))
double code(double p, double x) {
double tmp;
if (p <= -1.25e-42) {
tmp = sqrt(0.5);
} else if (p <= 4300000000000.0) {
tmp = 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 <= (-1.25d-42)) then
tmp = sqrt(0.5d0)
else if (p <= 4300000000000.0d0) then
tmp = 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 <= -1.25e-42) {
tmp = Math.sqrt(0.5);
} else if (p <= 4300000000000.0) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -1.25e-42: tmp = math.sqrt(0.5) elif p <= 4300000000000.0: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
function code(p, x) tmp = 0.0 if (p <= -1.25e-42) tmp = sqrt(0.5); elseif (p <= 4300000000000.0) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -1.25e-42) tmp = sqrt(0.5); elseif (p <= 4300000000000.0) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -1.25e-42], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 4300000000000.0], 1.0, N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -1.25 \cdot 10^{-42}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq 4300000000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < -1.25000000000000001e-42 or 4.3e12 < p Initial program 92.6%
Taylor expanded in x around 0 84.8%
if -1.25000000000000001e-42 < p < 4.3e12Initial program 72.0%
Taylor expanded in x around inf 62.2%
Final simplification76.2%
(FPCore (p x) :precision binary64 (if (<= p -8e-221) (/ p x) (/ (- p) x)))
double code(double p, double x) {
double tmp;
if (p <= -8e-221) {
tmp = p / x;
} else {
tmp = -p / x;
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= (-8d-221)) then
tmp = p / x
else
tmp = -p / x
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= -8e-221) {
tmp = p / x;
} else {
tmp = -p / x;
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -8e-221: tmp = p / x else: tmp = -p / x return tmp
function code(p, x) tmp = 0.0 if (p <= -8e-221) tmp = Float64(p / x); else tmp = Float64(Float64(-p) / x); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -8e-221) tmp = p / x; else tmp = -p / x; end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -8e-221], N[(p / x), $MachinePrecision], N[((-p) / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -8 \cdot 10^{-221}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-p}{x}\\
\end{array}
\end{array}
if p < -8.00000000000000014e-221Initial program 85.3%
Taylor expanded in x around -inf 12.8%
unpow212.8%
unpow212.8%
times-frac14.6%
Simplified14.6%
Taylor expanded in p around 0 18.1%
if -8.00000000000000014e-221 < p Initial program 84.3%
log1p-expm1-u84.3%
log1p-udef84.2%
+-commutative84.2%
distribute-rgt-in84.2%
metadata-eval84.2%
fma-def84.2%
Applied egg-rr84.3%
Taylor expanded in x around -inf 21.3%
associate-*r/21.3%
mul-1-neg21.3%
Simplified21.3%
Final simplification19.9%
(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 / 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}
Initial program 84.7%
Taylor expanded in x around -inf 13.3%
unpow213.3%
unpow213.3%
times-frac15.8%
Simplified15.8%
Taylor expanded in p around 0 11.1%
Final simplification11.1%
(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}
herbie shell --seed 2023193
(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))))))))