
(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 9 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}
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.999999996) (/ (- p_m) x) (sqrt (* 0.5 (log (exp (+ 1.0 (/ x (hypot x (* p_m 2.0))))))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p_m * 2.0))))))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) {
tmp = -p_m / x;
} else {
tmp = Math.sqrt((0.5 * Math.log(Math.exp((1.0 + (x / Math.hypot(x, (p_m * 2.0))))))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996: tmp = -p_m / x else: tmp = math.sqrt((0.5 * math.log(math.exp((1.0 + (x / math.hypot(x, (p_m * 2.0)))))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.999999996) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 * log(exp(Float64(1.0 + Float64(x / hypot(x, Float64(p_m * 2.0)))))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) tmp = -p_m / x; else tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p_m * 2.0)))))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.999999996], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[Log[N[Exp[N[(1.0 + N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.999999996:\\
\;\;\;\;\frac{-p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, p_m \cdot 2\right)}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.999999996000000002Initial program 18.4%
add-log-exp18.3%
+-commutative18.3%
add-sqr-sqrt18.3%
hypot-def18.3%
associate-*l*18.3%
sqrt-prod18.3%
metadata-eval18.3%
sqrt-unprod8.6%
add-sqr-sqrt18.3%
Applied egg-rr18.3%
Applied egg-rr18.3%
expm1-def18.3%
expm1-log1p18.3%
associate-/r/18.5%
*-commutative18.5%
Simplified18.5%
Taylor expanded in x around -inf 59.0%
associate-*r/59.0%
mul-1-neg59.0%
Simplified59.0%
if -0.999999996000000002 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
add-log-exp99.8%
+-commutative99.8%
add-sqr-sqrt99.8%
hypot-def99.8%
associate-*l*99.8%
sqrt-prod99.8%
metadata-eval99.8%
sqrt-unprod49.7%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Final simplification88.8%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.999999996) (/ (- p_m) x) (sqrt (+ 0.5 (* x (/ 0.5 (hypot x (* p_m 2.0))))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p_m * 2.0))))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) {
tmp = -p_m / x;
} else {
tmp = Math.sqrt((0.5 + (x * (0.5 / Math.hypot(x, (p_m * 2.0))))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996: tmp = -p_m / x else: tmp = math.sqrt((0.5 + (x * (0.5 / math.hypot(x, (p_m * 2.0)))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.999999996) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.5 / hypot(x, Float64(p_m * 2.0)))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.999999996) tmp = -p_m / x; else tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p_m * 2.0)))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.999999996], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 + N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.999999996:\\
\;\;\;\;\frac{-p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p_m \cdot 2\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.999999996000000002Initial program 18.4%
add-log-exp18.3%
+-commutative18.3%
add-sqr-sqrt18.3%
hypot-def18.3%
associate-*l*18.3%
sqrt-prod18.3%
metadata-eval18.3%
sqrt-unprod8.6%
add-sqr-sqrt18.3%
Applied egg-rr18.3%
Applied egg-rr18.3%
expm1-def18.3%
expm1-log1p18.3%
associate-/r/18.5%
*-commutative18.5%
Simplified18.5%
Taylor expanded in x around -inf 59.0%
associate-*r/59.0%
mul-1-neg59.0%
Simplified59.0%
if -0.999999996000000002 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
add-log-exp99.8%
+-commutative99.8%
add-sqr-sqrt99.8%
hypot-def99.8%
associate-*l*99.8%
sqrt-prod99.8%
metadata-eval99.8%
sqrt-unprod49.7%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Applied egg-rr98.8%
expm1-def98.8%
expm1-log1p99.8%
associate-/r/99.8%
*-commutative99.8%
Simplified99.8%
Final simplification88.8%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1.96) (/ (- p_m) x) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p_m 2.0) x)))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -1.96) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x)))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -1.96) {
tmp = -p_m / x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p_m * 2.0), x)))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -1.96: tmp = -p_m / x else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p_m * 2.0), x))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -1.96) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p_m * 2.0), x))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -1.96) tmp = -p_m / x; else tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -1.96], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p$95$m * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.96:\\
\;\;\;\;\frac{-p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p_m \cdot 2, x\right)}\right)}\\
\end{array}
\end{array}
if x < -1.96Initial program 48.1%
add-log-exp48.1%
+-commutative48.1%
add-sqr-sqrt48.1%
hypot-def48.3%
associate-*l*48.3%
sqrt-prod48.3%
metadata-eval48.3%
sqrt-unprod25.4%
add-sqr-sqrt48.3%
Applied egg-rr48.3%
Applied egg-rr47.7%
expm1-def47.7%
expm1-log1p48.2%
associate-/r/48.2%
*-commutative48.2%
Simplified48.2%
Taylor expanded in x around -inf 42.3%
associate-*r/42.3%
mul-1-neg42.3%
Simplified42.3%
if -1.96 < x Initial program 87.8%
add-sqr-sqrt87.8%
hypot-def87.8%
associate-*l*87.8%
sqrt-prod87.8%
metadata-eval87.8%
sqrt-unprod43.0%
add-sqr-sqrt87.8%
Applied egg-rr87.8%
Final simplification76.4%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ (- p_m) x)))
(if (<= x -2.65)
t_0
(if (<= x -3.5e-63)
(sqrt (+ 0.5 (/ (* x 0.25) p_m)))
(if (<= x -2.3e-70) t_0 (if (<= x 1e-28) (sqrt 0.5) 1.0))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (x <= -2.65) {
tmp = t_0;
} else if (x <= -3.5e-63) {
tmp = sqrt((0.5 + ((x * 0.25) / p_m)));
} else if (x <= -2.3e-70) {
tmp = t_0;
} else if (x <= 1e-28) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -p_m / x
if (x <= (-2.65d0)) then
tmp = t_0
else if (x <= (-3.5d-63)) then
tmp = sqrt((0.5d0 + ((x * 0.25d0) / p_m)))
else if (x <= (-2.3d-70)) then
tmp = t_0
else if (x <= 1d-28) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (x <= -2.65) {
tmp = t_0;
} else if (x <= -3.5e-63) {
tmp = Math.sqrt((0.5 + ((x * 0.25) / p_m)));
} else if (x <= -2.3e-70) {
tmp = t_0;
} else if (x <= 1e-28) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = -p_m / x tmp = 0 if x <= -2.65: tmp = t_0 elif x <= -3.5e-63: tmp = math.sqrt((0.5 + ((x * 0.25) / p_m))) elif x <= -2.3e-70: tmp = t_0 elif x <= 1e-28: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(Float64(-p_m) / x) tmp = 0.0 if (x <= -2.65) tmp = t_0; elseif (x <= -3.5e-63) tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.25) / p_m))); elseif (x <= -2.3e-70) tmp = t_0; elseif (x <= 1e-28) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = -p_m / x; tmp = 0.0; if (x <= -2.65) tmp = t_0; elseif (x <= -3.5e-63) tmp = sqrt((0.5 + ((x * 0.25) / p_m))); elseif (x <= -2.3e-70) tmp = t_0; elseif (x <= 1e-28) tmp = sqrt(0.5); else tmp = 1.0; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, If[LessEqual[x, -2.65], t$95$0, If[LessEqual[x, -3.5e-63], N[Sqrt[N[(0.5 + N[(N[(x * 0.25), $MachinePrecision] / p$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, -2.3e-70], t$95$0, If[LessEqual[x, 1e-28], N[Sqrt[0.5], $MachinePrecision], 1.0]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{-p_m}{x}\\
\mathbf{if}\;x \leq -2.65:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.5 \cdot 10^{-63}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p_m}}\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 10^{-28}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.64999999999999991 or -3.50000000000000003e-63 < x < -2.30000000000000001e-70Initial program 45.8%
add-log-exp45.8%
+-commutative45.8%
add-sqr-sqrt45.8%
hypot-def45.9%
associate-*l*45.9%
sqrt-prod45.9%
metadata-eval45.9%
sqrt-unprod23.4%
add-sqr-sqrt45.9%
Applied egg-rr45.9%
Applied egg-rr45.4%
expm1-def45.4%
expm1-log1p45.9%
associate-/r/45.9%
*-commutative45.9%
Simplified45.9%
Taylor expanded in x around -inf 41.8%
associate-*r/41.8%
mul-1-neg41.8%
Simplified41.8%
if -2.64999999999999991 < x < -3.50000000000000003e-63Initial program 73.8%
add-log-exp73.8%
+-commutative73.8%
add-sqr-sqrt73.8%
hypot-def73.8%
associate-*l*73.8%
sqrt-prod73.8%
metadata-eval73.8%
sqrt-unprod42.1%
add-sqr-sqrt73.8%
Applied egg-rr73.8%
Applied egg-rr72.8%
expm1-def72.8%
expm1-log1p73.8%
associate-/r/73.8%
*-commutative73.8%
Simplified73.8%
Taylor expanded in x around 0 72.6%
associate-*r/72.6%
Simplified72.6%
if -2.30000000000000001e-70 < x < 9.99999999999999971e-29Initial program 87.2%
Taylor expanded in x around 0 70.1%
if 9.99999999999999971e-29 < x Initial program 100.0%
add-log-exp100.0%
+-commutative100.0%
add-sqr-sqrt100.0%
hypot-def100.0%
associate-*l*100.0%
sqrt-prod100.0%
metadata-eval100.0%
sqrt-unprod50.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Applied egg-rr99.6%
expm1-def99.6%
expm1-log1p100.0%
associate-/r/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
Final simplification64.2%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1.05) (/ (- p_m) x) (if (<= x 3.7e-28) (sqrt 0.5) 1.0)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -1.05) {
tmp = -p_m / x;
} else if (x <= 3.7e-28) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-1.05d0)) then
tmp = -p_m / x
else if (x <= 3.7d-28) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -1.05) {
tmp = -p_m / x;
} else if (x <= 3.7e-28) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -1.05: tmp = -p_m / x elif x <= 3.7e-28: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -1.05) tmp = Float64(Float64(-p_m) / x); elseif (x <= 3.7e-28) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -1.05) tmp = -p_m / x; elseif (x <= 3.7e-28) tmp = sqrt(0.5); else tmp = 1.0; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -1.05], N[((-p$95$m) / x), $MachinePrecision], If[LessEqual[x, 3.7e-28], N[Sqrt[0.5], $MachinePrecision], 1.0]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05:\\
\;\;\;\;\frac{-p_m}{x}\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-28}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.05000000000000004Initial program 48.1%
add-log-exp48.1%
+-commutative48.1%
add-sqr-sqrt48.1%
hypot-def48.3%
associate-*l*48.3%
sqrt-prod48.3%
metadata-eval48.3%
sqrt-unprod25.4%
add-sqr-sqrt48.3%
Applied egg-rr48.3%
Applied egg-rr47.7%
expm1-def47.7%
expm1-log1p48.2%
associate-/r/48.2%
*-commutative48.2%
Simplified48.2%
Taylor expanded in x around -inf 42.3%
associate-*r/42.3%
mul-1-neg42.3%
Simplified42.3%
if -1.05000000000000004 < x < 3.7000000000000002e-28Initial program 80.7%
Taylor expanded in x around 0 67.8%
if 3.7000000000000002e-28 < x Initial program 100.0%
add-log-exp100.0%
+-commutative100.0%
add-sqr-sqrt100.0%
hypot-def100.0%
associate-*l*100.0%
sqrt-prod100.0%
metadata-eval100.0%
sqrt-unprod50.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Applied egg-rr99.6%
expm1-def99.6%
expm1-log1p100.0%
associate-/r/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
Final simplification63.7%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -4.8e-143) (/ (- p_m) x) 1.0))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -4.8e-143) {
tmp = -p_m / x;
} else {
tmp = 1.0;
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.8d-143)) then
tmp = -p_m / x
else
tmp = 1.0d0
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -4.8e-143) {
tmp = -p_m / x;
} else {
tmp = 1.0;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -4.8e-143: tmp = -p_m / x else: tmp = 1.0 return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -4.8e-143) tmp = Float64(Float64(-p_m) / x); else tmp = 1.0; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -4.8e-143) tmp = -p_m / x; else tmp = 1.0; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -4.8e-143], N[((-p$95$m) / x), $MachinePrecision], 1.0]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-143}:\\
\;\;\;\;\frac{-p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -4.7999999999999998e-143Initial program 58.6%
add-log-exp58.6%
+-commutative58.6%
add-sqr-sqrt58.6%
hypot-def58.6%
associate-*l*58.6%
sqrt-prod58.6%
metadata-eval58.6%
sqrt-unprod32.8%
add-sqr-sqrt58.6%
Applied egg-rr58.6%
Applied egg-rr57.9%
expm1-def57.9%
expm1-log1p58.6%
associate-/r/58.7%
*-commutative58.7%
Simplified58.7%
Taylor expanded in x around -inf 31.6%
associate-*r/31.6%
mul-1-neg31.6%
Simplified31.6%
if -4.7999999999999998e-143 < x Initial program 100.0%
add-log-exp100.0%
+-commutative100.0%
add-sqr-sqrt100.0%
hypot-def100.0%
associate-*l*100.0%
sqrt-prod100.0%
metadata-eval100.0%
sqrt-unprod45.4%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Applied egg-rr99.3%
expm1-def99.3%
expm1-log1p100.0%
associate-/r/100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 64.3%
Final simplification46.8%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -9.5e+24) (reciprocal (/ x p_m)) 1.0))
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{reciprocal}\left(\left(\frac{x}{p_m}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -9.5000000000000001e24Initial program 50.9%
Taylor expanded in x around -inf 44.0%
associate-*r/44.0%
Simplified44.0%
associate-*r/44.0%
sqrt-div60.1%
associate-*r*60.1%
metadata-eval60.1%
*-un-lft-identity60.1%
unpow260.1%
sqrt-prod33.6%
add-sqr-sqrt44.2%
unpow244.2%
sqrt-prod0.0%
add-sqr-sqrt45.4%
clear-num45.4%
reciprocal-define29.4%
Applied egg-rr29.4%
if -9.5000000000000001e24 < x Initial program 85.0%
add-log-exp85.0%
+-commutative85.0%
add-sqr-sqrt85.0%
hypot-def85.0%
associate-*l*85.0%
sqrt-prod85.0%
metadata-eval85.0%
sqrt-unprod42.0%
add-sqr-sqrt85.0%
Applied egg-rr85.0%
Applied egg-rr84.3%
expm1-def84.3%
expm1-log1p85.0%
associate-/r/85.1%
*-commutative85.1%
Simplified85.1%
Taylor expanded in x around inf 43.8%
Final simplification40.8%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -9.2e+25) (/ p_m x) 1.0))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -9.2e+25) {
tmp = p_m / x;
} else {
tmp = 1.0;
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-9.2d+25)) then
tmp = p_m / x
else
tmp = 1.0d0
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -9.2e+25) {
tmp = p_m / x;
} else {
tmp = 1.0;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -9.2e+25: tmp = p_m / x else: tmp = 1.0 return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -9.2e+25) tmp = Float64(p_m / x); else tmp = 1.0; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -9.2e+25) tmp = p_m / x; else tmp = 1.0; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -9.2e+25], N[(p$95$m / x), $MachinePrecision], 1.0]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -9.1999999999999992e25Initial program 50.9%
Taylor expanded in x around -inf 44.0%
associate-*r/44.0%
Simplified44.0%
Taylor expanded in p around 0 45.4%
if -9.1999999999999992e25 < x Initial program 85.0%
add-log-exp85.0%
+-commutative85.0%
add-sqr-sqrt85.0%
hypot-def85.0%
associate-*l*85.0%
sqrt-prod85.0%
metadata-eval85.0%
sqrt-unprod42.0%
add-sqr-sqrt85.0%
Applied egg-rr85.0%
Applied egg-rr84.3%
expm1-def84.3%
expm1-log1p85.0%
associate-/r/85.1%
*-commutative85.1%
Simplified85.1%
Taylor expanded in x around inf 43.8%
Final simplification44.2%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 1.0)
p_m = fabs(p);
double code(double p_m, double x) {
return 1.0;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = 1.0d0
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return 1.0;
}
p_m = math.fabs(p) def code(p_m, x): return 1.0
p_m = abs(p) function code(p_m, x) return 1.0 end
p_m = abs(p); function tmp = code(p_m, x) tmp = 1.0; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := 1.0
\begin{array}{l}
p_m = \left|p\right|
\\
1
\end{array}
Initial program 77.8%
add-log-exp77.8%
+-commutative77.8%
add-sqr-sqrt77.8%
hypot-def77.9%
associate-*l*77.9%
sqrt-prod77.9%
metadata-eval77.9%
sqrt-unprod38.6%
add-sqr-sqrt77.9%
Applied egg-rr77.9%
Applied egg-rr77.2%
expm1-def77.2%
expm1-log1p77.8%
associate-/r/77.9%
*-commutative77.9%
Simplified77.9%
Taylor expanded in x around inf 36.5%
Final simplification36.5%
(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 2024024
(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))))))))