
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (let* ((t_0 (* (hypot 1.0 z) (sqrt y)))) (* x_s (/ (/ 1.0 (* x_m t_0)) t_0))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double t_0 = hypot(1.0, z) * sqrt(y);
return x_s * ((1.0 / (x_m * t_0)) / t_0);
}
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double t_0 = Math.hypot(1.0, z) * Math.sqrt(y);
return x_s * ((1.0 / (x_m * t_0)) / t_0);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): t_0 = math.hypot(1.0, z) * math.sqrt(y) return x_s * ((1.0 / (x_m * t_0)) / t_0)
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) t_0 = Float64(hypot(1.0, z) * sqrt(y)) return Float64(x_s * Float64(Float64(1.0 / Float64(x_m * t_0)) / t_0)) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
t_0 = hypot(1.0, z) * sqrt(y);
tmp = x_s * ((1.0 / (x_m * t_0)) / t_0);
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * N[Sqrt[y], $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * N[(N[(1.0 / N[(x$95$m * t$95$0), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(1, z\right) \cdot \sqrt{y}\\
x\_s \cdot \frac{\frac{1}{x\_m \cdot t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 92.8%
associate-/l/91.9%
associate-*l*90.4%
*-commutative90.4%
sqr-neg90.4%
+-commutative90.4%
sqr-neg90.4%
fma-define90.4%
Simplified90.4%
associate-*r*91.8%
*-commutative91.8%
associate-/r*92.2%
*-commutative92.2%
associate-/l/92.7%
fma-undefine92.7%
+-commutative92.7%
associate-/r*92.8%
*-un-lft-identity92.8%
add-sqr-sqrt47.7%
times-frac47.6%
+-commutative47.6%
fma-undefine47.6%
*-commutative47.6%
sqrt-prod47.7%
fma-undefine47.7%
+-commutative47.7%
hypot-1-def47.7%
+-commutative47.7%
Applied egg-rr51.7%
associate-*l/51.7%
*-lft-identity51.7%
associate-/l/51.6%
*-commutative51.6%
Simplified51.6%
Final simplification51.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ (pow (* (hypot 1.0 z) (sqrt x_m)) -2.0) y)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * (pow((hypot(1.0, z) * sqrt(x_m)), -2.0) / y);
}
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (Math.pow((Math.hypot(1.0, z) * Math.sqrt(x_m)), -2.0) / y);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * (math.pow((math.hypot(1.0, z) * math.sqrt(x_m)), -2.0) / y)
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64((Float64(hypot(1.0, z) * sqrt(x_m)) ^ -2.0) / y)) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * (((hypot(1.0, z) * sqrt(x_m)) ^ -2.0) / y);
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(N[Power[N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * N[Sqrt[x$95$m], $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{{\left(\mathsf{hypot}\left(1, z\right) \cdot \sqrt{x\_m}\right)}^{-2}}{y}
\end{array}
Initial program 92.8%
associate-/l/91.9%
associate-*l*90.4%
*-commutative90.4%
sqr-neg90.4%
+-commutative90.4%
sqr-neg90.4%
fma-define90.4%
Simplified90.4%
associate-*r*91.8%
*-commutative91.8%
associate-/r*92.2%
*-commutative92.2%
associate-/l/92.7%
fma-undefine92.7%
+-commutative92.7%
associate-/r*92.8%
*-un-lft-identity92.8%
add-sqr-sqrt47.7%
times-frac47.6%
+-commutative47.6%
fma-undefine47.6%
*-commutative47.6%
sqrt-prod47.7%
fma-undefine47.7%
+-commutative47.7%
hypot-1-def47.7%
+-commutative47.7%
Applied egg-rr51.7%
associate-*l/51.7%
*-lft-identity51.7%
associate-/l/51.6%
*-commutative51.6%
Simplified51.6%
Taylor expanded in x around 0 91.9%
+-commutative91.9%
unpow291.9%
fma-undefine91.9%
associate-/l/92.8%
associate-/r*92.8%
associate-/l/91.1%
*-commutative91.1%
rem-square-sqrt91.1%
fma-undefine91.1%
unpow291.1%
+-commutative91.1%
metadata-eval91.1%
unpow291.1%
hypot-undefine91.1%
fma-undefine91.1%
unpow291.1%
+-commutative91.1%
metadata-eval91.1%
unpow291.1%
hypot-undefine91.1%
rem-square-sqrt51.4%
Simplified53.3%
Final simplification53.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ 1.0 (* y (* (hypot 1.0 z) (* x_m (hypot 1.0 z)))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (y * (hypot(1.0, z) * (x_m * hypot(1.0, z)))));
}
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (y * (Math.hypot(1.0, z) * (x_m * Math.hypot(1.0, z)))));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * (1.0 / (y * (math.hypot(1.0, z) * (x_m * math.hypot(1.0, z)))))
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(1.0 / Float64(y * Float64(hypot(1.0, z) * Float64(x_m * hypot(1.0, z)))))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * (1.0 / (y * (hypot(1.0, z) * (x_m * hypot(1.0, z)))));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(1.0 / N[(y * N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * N[(x$95$m * N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{1}{y \cdot \left(\mathsf{hypot}\left(1, z\right) \cdot \left(x\_m \cdot \mathsf{hypot}\left(1, z\right)\right)\right)}
\end{array}
Initial program 92.8%
associate-/l/91.9%
associate-*l*90.4%
*-commutative90.4%
sqr-neg90.4%
+-commutative90.4%
sqr-neg90.4%
fma-define90.4%
Simplified90.4%
add-sqr-sqrt51.2%
pow251.2%
*-commutative51.2%
sqrt-prod51.2%
fma-undefine51.2%
+-commutative51.2%
hypot-1-def53.1%
Applied egg-rr53.1%
unpow253.1%
associate-*l*53.1%
*-commutative53.1%
associate-*l*53.1%
add-sqr-sqrt93.7%
Applied egg-rr93.7%
Final simplification93.7%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (* y (+ 1.0 (* z z))) 5e+306)
(/ (/ 1.0 x_m) (fma (* z y) z y))
(/ (* (/ -1.0 y) (/ -1.0 (* x_m z))) z))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if ((y * (1.0 + (z * z))) <= 5e+306) {
tmp = (1.0 / x_m) / fma((z * y), z, y);
} else {
tmp = ((-1.0 / y) * (-1.0 / (x_m * z))) / z;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+306) tmp = Float64(Float64(1.0 / x_m) / fma(Float64(z * y), z, y)); else tmp = Float64(Float64(Float64(-1.0 / y) * Float64(-1.0 / Float64(x_m * z))) / z); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+306], N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(z * y), $MachinePrecision] * z + y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 / y), $MachinePrecision] * N[(-1.0 / N[(x$95$m * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+306}:\\
\;\;\;\;\frac{\frac{1}{x\_m}}{\mathsf{fma}\left(z \cdot y, z, y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-1}{y} \cdot \frac{-1}{x\_m \cdot z}}{z}\\
\end{array}
\end{array}
if (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) < 4.99999999999999993e306Initial program 96.2%
+-commutative96.2%
distribute-lft-in96.2%
associate-*r*97.6%
*-rgt-identity97.6%
fma-define97.6%
Applied egg-rr97.6%
if 4.99999999999999993e306 < (*.f64 y (+.f64 #s(literal 1 binary64) (*.f64 z z))) Initial program 74.1%
associate-/l/74.1%
associate-*l*78.7%
*-commutative78.7%
sqr-neg78.7%
+-commutative78.7%
sqr-neg78.7%
fma-define78.7%
Simplified78.7%
Taylor expanded in z around inf 74.1%
associate-*r*78.5%
associate-/r*78.6%
Simplified78.6%
associate-/r*78.5%
div-inv78.5%
unpow278.5%
times-frac99.7%
Applied egg-rr99.7%
frac-2neg99.7%
associate-*r/97.4%
associate-/l/95.1%
*-commutative95.1%
distribute-neg-frac95.1%
metadata-eval95.1%
Applied egg-rr95.1%
Final simplification97.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (* z z) 1e+80)
(/ (/ 1.0 x_m) (* y (+ 1.0 (* z z))))
(/ (/ 1.0 y) (* z (* x_m z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if ((z * z) <= 1e+80) {
tmp = (1.0 / x_m) / (y * (1.0 + (z * z)));
} else {
tmp = (1.0 / y) / (z * (x_m * z));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z * z) <= 1d+80) then
tmp = (1.0d0 / x_m) / (y * (1.0d0 + (z * z)))
else
tmp = (1.0d0 / y) / (z * (x_m * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if ((z * z) <= 1e+80) {
tmp = (1.0 / x_m) / (y * (1.0 + (z * z)));
} else {
tmp = (1.0 / y) / (z * (x_m * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): tmp = 0 if (z * z) <= 1e+80: tmp = (1.0 / x_m) / (y * (1.0 + (z * z))) else: tmp = (1.0 / y) / (z * (x_m * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(z * z) <= 1e+80) tmp = Float64(Float64(1.0 / x_m) / Float64(y * Float64(1.0 + Float64(z * z)))); else tmp = Float64(Float64(1.0 / y) / Float64(z * Float64(x_m * z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
tmp = 0.0;
if ((z * z) <= 1e+80)
tmp = (1.0 / x_m) / (y * (1.0 + (z * z)));
else
tmp = (1.0 / y) / (z * (x_m * z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(z * z), $MachinePrecision], 1e+80], N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] / N[(z * N[(x$95$m * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+80}:\\
\;\;\;\;\frac{\frac{1}{x\_m}}{y \cdot \left(1 + z \cdot z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{y}}{z \cdot \left(x\_m \cdot z\right)}\\
\end{array}
\end{array}
if (*.f64 z z) < 1e80Initial program 99.7%
if 1e80 < (*.f64 z z) Initial program 82.0%
associate-/l/81.1%
associate-*l*77.2%
*-commutative77.2%
sqr-neg77.2%
+-commutative77.2%
sqr-neg77.2%
fma-define77.2%
Simplified77.2%
Taylor expanded in z around inf 81.1%
associate-*r*80.9%
associate-/r*81.8%
Simplified81.8%
associate-/r*81.7%
div-inv81.7%
unpow281.7%
times-frac96.8%
Applied egg-rr96.8%
clear-num95.5%
frac-times86.2%
*-un-lft-identity86.2%
div-inv86.2%
clear-num86.3%
/-rgt-identity86.3%
*-commutative86.3%
Applied egg-rr86.3%
Final simplification94.5%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= z 1.0) (/ (/ 1.0 x_m) y) (/ 1.0 (* (* z y) (* x_m z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= 1.0) {
tmp = (1.0 / x_m) / y;
} else {
tmp = 1.0 / ((z * y) * (x_m * z));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= 1.0d0) then
tmp = (1.0d0 / x_m) / y
else
tmp = 1.0d0 / ((z * y) * (x_m * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= 1.0) {
tmp = (1.0 / x_m) / y;
} else {
tmp = 1.0 / ((z * y) * (x_m * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): tmp = 0 if z <= 1.0: tmp = (1.0 / x_m) / y else: tmp = 1.0 / ((z * y) * (x_m * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= 1.0) tmp = Float64(Float64(1.0 / x_m) / y); else tmp = Float64(1.0 / Float64(Float64(z * y) * Float64(x_m * z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
tmp = 0.0;
if (z <= 1.0)
tmp = (1.0 / x_m) / y;
else
tmp = 1.0 / ((z * y) * (x_m * z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, 1.0], N[(N[(1.0 / x$95$m), $MachinePrecision] / y), $MachinePrecision], N[(1.0 / N[(N[(z * y), $MachinePrecision] * N[(x$95$m * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq 1:\\
\;\;\;\;\frac{\frac{1}{x\_m}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(z \cdot y\right) \cdot \left(x\_m \cdot z\right)}\\
\end{array}
\end{array}
if z < 1Initial program 95.6%
Taylor expanded in z around 0 74.9%
if 1 < z Initial program 82.5%
associate-/l/82.5%
associate-*l*79.0%
*-commutative79.0%
sqr-neg79.0%
+-commutative79.0%
sqr-neg79.0%
fma-define79.0%
Simplified79.0%
Taylor expanded in z around inf 82.2%
associate-*r*81.9%
associate-/r*82.0%
Simplified82.0%
associate-/r*81.8%
div-inv81.9%
unpow281.9%
times-frac98.9%
Applied egg-rr98.9%
*-commutative98.9%
associate-/r*97.4%
clear-num95.7%
frac-times95.7%
metadata-eval95.7%
div-inv95.7%
clear-num95.8%
/-rgt-identity95.8%
*-commutative95.8%
Applied egg-rr95.8%
Final simplification79.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= z 1.0) (/ (/ 1.0 x_m) y) (/ (/ 1.0 y) (* z (* x_m z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= 1.0) {
tmp = (1.0 / x_m) / y;
} else {
tmp = (1.0 / y) / (z * (x_m * z));
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= 1.0d0) then
tmp = (1.0d0 / x_m) / y
else
tmp = (1.0d0 / y) / (z * (x_m * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= 1.0) {
tmp = (1.0 / x_m) / y;
} else {
tmp = (1.0 / y) / (z * (x_m * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): tmp = 0 if z <= 1.0: tmp = (1.0 / x_m) / y else: tmp = (1.0 / y) / (z * (x_m * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= 1.0) tmp = Float64(Float64(1.0 / x_m) / y); else tmp = Float64(Float64(1.0 / y) / Float64(z * Float64(x_m * z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
tmp = 0.0;
if (z <= 1.0)
tmp = (1.0 / x_m) / y;
else
tmp = (1.0 / y) / (z * (x_m * z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, 1.0], N[(N[(1.0 / x$95$m), $MachinePrecision] / y), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] / N[(z * N[(x$95$m * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq 1:\\
\;\;\;\;\frac{\frac{1}{x\_m}}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{y}}{z \cdot \left(x\_m \cdot z\right)}\\
\end{array}
\end{array}
if z < 1Initial program 95.6%
Taylor expanded in z around 0 74.9%
if 1 < z Initial program 82.5%
associate-/l/82.5%
associate-*l*79.0%
*-commutative79.0%
sqr-neg79.0%
+-commutative79.0%
sqr-neg79.0%
fma-define79.0%
Simplified79.0%
Taylor expanded in z around inf 82.2%
associate-*r*81.9%
associate-/r*82.0%
Simplified82.0%
associate-/r*81.8%
div-inv81.9%
unpow281.9%
times-frac98.9%
Applied egg-rr98.9%
clear-num97.3%
frac-times87.3%
*-un-lft-identity87.3%
div-inv87.3%
clear-num87.3%
/-rgt-identity87.3%
*-commutative87.3%
Applied egg-rr87.3%
Final simplification77.5%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ 1.0 (* x_m y))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (x_m * y));
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (1.0d0 / (x_m * y))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (1.0 / (x_m * y));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * (1.0 / (x_m * y))
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(1.0 / Float64(x_m * y))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * (1.0 / (x_m * y));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(1.0 / N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{1}{x\_m \cdot y}
\end{array}
Initial program 92.8%
associate-/l/91.9%
associate-*l*90.4%
*-commutative90.4%
sqr-neg90.4%
+-commutative90.4%
sqr-neg90.4%
fma-define90.4%
Simplified90.4%
Taylor expanded in z around 0 63.1%
Final simplification63.1%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (/ (/ 1.0 x_m) y)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * ((1.0 / x_m) / y);
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * ((1.0d0 / x_m) / y)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * ((1.0 / x_m) / y);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * ((1.0 / x_m) / y)
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(Float64(1.0 / x_m) / y)) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * ((1.0 / x_m) / y);
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(N[(1.0 / x$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \frac{\frac{1}{x\_m}}{y}
\end{array}
Initial program 92.8%
Taylor expanded in z around 0 63.2%
Final simplification63.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* z z))) (t_1 (* y t_0)) (t_2 (/ (/ 1.0 y) (* t_0 x))))
(if (< t_1 (- INFINITY))
t_2
(if (< t_1 8.680743250567252e+305) (/ (/ 1.0 x) (* t_0 y)) t_2))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (z * z);
double t_1 = y * t_0;
double t_2 = (1.0 / y) / (t_0 * x);
double tmp;
if (t_1 < -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 < 8.680743250567252e+305) {
tmp = (1.0 / x) / (t_0 * y);
} else {
tmp = t_2;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (z * z);
double t_1 = y * t_0;
double t_2 = (1.0 / y) / (t_0 * x);
double tmp;
if (t_1 < -Double.POSITIVE_INFINITY) {
tmp = t_2;
} else if (t_1 < 8.680743250567252e+305) {
tmp = (1.0 / x) / (t_0 * y);
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (z * z) t_1 = y * t_0 t_2 = (1.0 / y) / (t_0 * x) tmp = 0 if t_1 < -math.inf: tmp = t_2 elif t_1 < 8.680743250567252e+305: tmp = (1.0 / x) / (t_0 * y) else: tmp = t_2 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(z * z)) t_1 = Float64(y * t_0) t_2 = Float64(Float64(1.0 / y) / Float64(t_0 * x)) tmp = 0.0 if (t_1 < Float64(-Inf)) tmp = t_2; elseif (t_1 < 8.680743250567252e+305) tmp = Float64(Float64(1.0 / x) / Float64(t_0 * y)); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (z * z); t_1 = y * t_0; t_2 = (1.0 / y) / (t_0 * x); tmp = 0.0; if (t_1 < -Inf) tmp = t_2; elseif (t_1 < 8.680743250567252e+305) tmp = (1.0 / x) / (t_0 * y); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / y), $MachinePrecision] / N[(t$95$0 * x), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$1, (-Infinity)], t$95$2, If[Less[t$95$1, 8.680743250567252e+305], N[(N[(1.0 / x), $MachinePrecision] / N[(t$95$0 * y), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + z \cdot z\\
t_1 := y \cdot t\_0\\
t_2 := \frac{\frac{1}{y}}{t\_0 \cdot x}\\
\mathbf{if}\;t\_1 < -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 < 8.680743250567252 \cdot 10^{+305}:\\
\;\;\;\;\frac{\frac{1}{x}}{t\_0 \cdot y}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
herbie shell --seed 2024066
(FPCore (x y z)
:name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
:precision binary64
:alt
(if (< (* y (+ 1.0 (* z z))) (- INFINITY)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x)) (if (< (* y (+ 1.0 (* z z))) 8.680743250567252e+305) (/ (/ 1.0 x) (* (+ 1.0 (* z z)) y)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x))))
(/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))