
(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 7 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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z z) 1e+178) (/ (/ 1.0 (* x y)) (+ 1.0 (* z z))) (* (/ 1.0 z) (/ 1.0 (* x (* z y))))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+178) {
tmp = (1.0 / (x * y)) / (1.0 + (z * z));
} else {
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z * z) <= 1d+178) then
tmp = (1.0d0 / (x * y)) / (1.0d0 + (z * z))
else
tmp = (1.0d0 / z) * (1.0d0 / (x * (z * y)))
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+178) {
tmp = (1.0 / (x * y)) / (1.0 + (z * z));
} else {
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z * z) <= 1e+178: tmp = (1.0 / (x * y)) / (1.0 + (z * z)) else: tmp = (1.0 / z) * (1.0 / (x * (z * y))) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e+178) tmp = Float64(Float64(1.0 / Float64(x * y)) / Float64(1.0 + Float64(z * z))); else tmp = Float64(Float64(1.0 / z) * Float64(1.0 / Float64(x * Float64(z * y)))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z * z) <= 1e+178)
tmp = (1.0 / (x * y)) / (1.0 + (z * z));
else
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+178], N[(N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / z), $MachinePrecision] * N[(1.0 / N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+178}:\\
\;\;\;\;\frac{\frac{1}{x \cdot y}}{1 + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z} \cdot \frac{1}{x \cdot \left(z \cdot y\right)}\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e178Initial program 98.4%
associate-/r*99.0%
Simplified99.0%
add-sqr-sqrt46.7%
sqrt-unprod41.1%
frac-times32.1%
inv-pow32.1%
inv-pow32.1%
pow-prod-up32.1%
metadata-eval32.1%
Applied egg-rr32.1%
metadata-eval32.1%
pow-sqr32.1%
unpow-132.1%
unpow-132.1%
times-frac41.1%
associate-/r*41.1%
*-commutative41.1%
associate-/r*41.1%
*-commutative41.1%
unpow-141.1%
unpow-141.1%
pow-sqr41.1%
metadata-eval41.1%
Simplified41.1%
sqrt-pow199.1%
metadata-eval99.1%
inv-pow99.1%
*-commutative99.1%
Applied egg-rr99.1%
if 1.0000000000000001e178 < (*.f64 z z) Initial program 77.3%
associate-/r*77.3%
+-commutative77.3%
fma-def77.3%
Simplified77.3%
Taylor expanded in z around inf 78.3%
unpow278.3%
*-commutative78.3%
associate-*l*78.9%
*-commutative78.9%
associate-*l*87.8%
Simplified87.8%
Taylor expanded in z around 0 97.7%
associate-/r*97.7%
div-inv97.8%
*-commutative97.8%
*-commutative97.8%
associate-*l*96.7%
*-commutative96.7%
Applied egg-rr96.7%
Final simplification98.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (/ (/ 1.0 (* (hypot 1.0 z) x)) (* (hypot 1.0 z) y)))
assert(x < y);
double code(double x, double y, double z) {
return (1.0 / (hypot(1.0, z) * x)) / (hypot(1.0, z) * y);
}
assert x < y;
public static double code(double x, double y, double z) {
return (1.0 / (Math.hypot(1.0, z) * x)) / (Math.hypot(1.0, z) * y);
}
[x, y] = sort([x, y]) def code(x, y, z): return (1.0 / (math.hypot(1.0, z) * x)) / (math.hypot(1.0, z) * y)
x, y = sort([x, y]) function code(x, y, z) return Float64(Float64(1.0 / Float64(hypot(1.0, z) * x)) / Float64(hypot(1.0, z) * y)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = (1.0 / (hypot(1.0, z) * x)) / (hypot(1.0, z) * y);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(1.0 / N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{\frac{1}{\mathsf{hypot}\left(1, z\right) \cdot x}}{\mathsf{hypot}\left(1, z\right) \cdot y}
\end{array}
Initial program 90.9%
associate-/r*90.5%
+-commutative90.5%
fma-def90.5%
Simplified90.5%
fma-udef90.5%
+-commutative90.5%
associate-/r*90.9%
associate-/r*91.8%
div-inv91.7%
add-sqr-sqrt91.7%
times-frac92.3%
hypot-1-def92.3%
hypot-1-def98.1%
Applied egg-rr98.1%
associate-/l/98.2%
un-div-inv98.2%
associate-/l/98.1%
Applied egg-rr98.1%
Final simplification98.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z z) 1e+178) (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))) (* (/ 1.0 z) (/ 1.0 (* x (* z y))))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+178) {
tmp = (1.0 / x) / (y * (1.0 + (z * z)));
} else {
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z * z) <= 1d+178) then
tmp = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
else
tmp = (1.0d0 / z) * (1.0d0 / (x * (z * y)))
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+178) {
tmp = (1.0 / x) / (y * (1.0 + (z * z)));
} else {
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z * z) <= 1e+178: tmp = (1.0 / x) / (y * (1.0 + (z * z))) else: tmp = (1.0 / z) * (1.0 / (x * (z * y))) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e+178) tmp = Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))); else tmp = Float64(Float64(1.0 / z) * Float64(1.0 / Float64(x * Float64(z * y)))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z * z) <= 1e+178)
tmp = (1.0 / x) / (y * (1.0 + (z * z)));
else
tmp = (1.0 / z) * (1.0 / (x * (z * y)));
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+178], N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / z), $MachinePrecision] * N[(1.0 / N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+178}:\\
\;\;\;\;\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z} \cdot \frac{1}{x \cdot \left(z \cdot y\right)}\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e178Initial program 98.4%
if 1.0000000000000001e178 < (*.f64 z z) Initial program 77.3%
associate-/r*77.3%
+-commutative77.3%
fma-def77.3%
Simplified77.3%
Taylor expanded in z around inf 78.3%
unpow278.3%
*-commutative78.3%
associate-*l*78.9%
*-commutative78.9%
associate-*l*87.8%
Simplified87.8%
Taylor expanded in z around 0 97.7%
associate-/r*97.7%
div-inv97.8%
*-commutative97.8%
*-commutative97.8%
associate-*l*96.7%
*-commutative96.7%
Applied egg-rr96.7%
Final simplification97.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (/ 1.0 (* x (* z (* z y)))) (/ 1.0 (* x y))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = 1.0 / (x * (z * (z * y)));
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = 1.0d0 / (x * (z * (z * y)))
else
tmp = 1.0d0 / (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = 1.0 / (x * (z * (z * y)));
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = 1.0 / (x * (z * (z * y))) else: tmp = 1.0 / (x * y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(1.0 / Float64(x * Float64(z * Float64(z * y)))); else tmp = Float64(1.0 / Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.0) || ~((z <= 1.0)))
tmp = 1.0 / (x * (z * (z * y)));
else
tmp = 1.0 / (x * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(1.0 / N[(x * N[(z * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\frac{1}{x \cdot \left(z \cdot \left(z \cdot y\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot y}\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 82.4%
associate-/r*81.6%
+-commutative81.6%
fma-def81.6%
Simplified81.6%
Taylor expanded in z around inf 81.6%
unpow281.6%
associate-*r*89.0%
*-commutative89.0%
Simplified89.0%
if -1 < z < 1Initial program 99.6%
associate-/r*99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around 0 99.1%
Final simplification94.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z z) 0.1) (/ 1.0 (* x y)) (/ 1.0 (* z (* x (* z y))))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 0.1) {
tmp = 1.0 / (x * y);
} else {
tmp = 1.0 / (z * (x * (z * y)));
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z * z) <= 0.1d0) then
tmp = 1.0d0 / (x * y)
else
tmp = 1.0d0 / (z * (x * (z * y)))
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 0.1) {
tmp = 1.0 / (x * y);
} else {
tmp = 1.0 / (z * (x * (z * y)));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z * z) <= 0.1: tmp = 1.0 / (x * y) else: tmp = 1.0 / (z * (x * (z * y))) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 0.1) tmp = Float64(1.0 / Float64(x * y)); else tmp = Float64(1.0 / Float64(z * Float64(x * Float64(z * y)))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z * z) <= 0.1)
tmp = 1.0 / (x * y);
else
tmp = 1.0 / (z * (x * (z * y)));
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 0.1], N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 0.1:\\
\;\;\;\;\frac{1}{x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \left(x \cdot \left(z \cdot y\right)\right)}\\
\end{array}
\end{array}
if (*.f64 z z) < 0.10000000000000001Initial program 99.6%
associate-/r*99.7%
+-commutative99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around 0 99.1%
if 0.10000000000000001 < (*.f64 z z) Initial program 82.4%
associate-/r*81.6%
+-commutative81.6%
fma-def81.6%
Simplified81.6%
Taylor expanded in z around inf 83.1%
unpow283.1%
*-commutative83.1%
associate-*l*83.5%
*-commutative83.5%
associate-*l*89.8%
Simplified89.8%
Taylor expanded in z around 0 97.5%
expm1-log1p-u63.4%
expm1-udef40.3%
*-commutative40.3%
*-commutative40.3%
associate-*l*39.0%
*-commutative39.0%
Applied egg-rr39.0%
expm1-def62.1%
expm1-log1p96.1%
*-commutative96.1%
Simplified96.1%
Final simplification97.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.3e+61))) (/ -1.0 (* x (* z y))) (/ 1.0 (* x y))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.3e+61)) {
tmp = -1.0 / (x * (z * y));
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 1.3d+61))) then
tmp = (-1.0d0) / (x * (z * y))
else
tmp = 1.0d0 / (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.3e+61)) {
tmp = -1.0 / (x * (z * y));
} else {
tmp = 1.0 / (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.3e+61): tmp = -1.0 / (x * (z * y)) else: tmp = 1.0 / (x * y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.3e+61)) tmp = Float64(-1.0 / Float64(x * Float64(z * y))); else tmp = Float64(1.0 / Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.0) || ~((z <= 1.3e+61)))
tmp = -1.0 / (x * (z * y));
else
tmp = 1.0 / (x * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.3e+61]], $MachinePrecision]], N[(-1.0 / N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1.3 \cdot 10^{+61}\right):\\
\;\;\;\;\frac{-1}{x \cdot \left(z \cdot y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot y}\\
\end{array}
\end{array}
if z < -1 or 1.29999999999999986e61 < z Initial program 80.8%
associate-/r*80.6%
+-commutative80.6%
fma-def80.6%
Simplified80.6%
fma-udef80.6%
+-commutative80.6%
associate-/r*80.8%
associate-/r*82.8%
div-inv82.8%
add-sqr-sqrt82.8%
times-frac84.0%
hypot-1-def84.0%
hypot-1-def96.6%
Applied egg-rr96.6%
associate-/l/96.7%
un-div-inv96.7%
associate-/l/96.5%
Applied egg-rr96.5%
Taylor expanded in z around -inf 78.8%
Taylor expanded in z around 0 45.5%
associate-*r*42.6%
*-commutative42.6%
*-commutative42.6%
Simplified42.6%
if -1 < z < 1.29999999999999986e61Initial program 99.6%
associate-/r*99.1%
+-commutative99.1%
fma-def99.1%
Simplified99.1%
Taylor expanded in z around 0 93.7%
Final simplification69.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (/ 1.0 (* x y)))
assert(x < y);
double code(double x, double y, double z) {
return 1.0 / (x * y);
}
NOTE: x and y should be sorted in increasing order before calling this function.
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)
end function
assert x < y;
public static double code(double x, double y, double z) {
return 1.0 / (x * y);
}
[x, y] = sort([x, y]) def code(x, y, z): return 1.0 / (x * y)
x, y = sort([x, y]) function code(x, y, z) return Float64(1.0 / Float64(x * y)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = 1.0 / (x * y);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(1.0 / N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{1}{x \cdot y}
\end{array}
Initial program 90.9%
associate-/r*90.5%
+-commutative90.5%
fma-def90.5%
Simplified90.5%
Taylor expanded in z around 0 59.7%
Final simplification59.7%
(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 2023196
(FPCore (x y z)
:name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(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)))))