
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + 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 = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + 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 = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ x (/ z y))))
double code(double x, double y, double z) {
return x + (x / (z / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (x / (z / y))
end function
public static double code(double x, double y, double z) {
return x + (x / (z / y));
}
def code(x, y, z): return x + (x / (z / y))
function code(x, y, z) return Float64(x + Float64(x / Float64(z / y))) end
function tmp = code(x, y, z) tmp = x + (x / (z / y)); end
code[x_, y_, z_] := N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x}{\frac{z}{y}}
\end{array}
Initial program 82.6%
associate-/l*95.8%
remove-double-neg95.8%
distribute-frac-neg295.8%
neg-sub095.8%
remove-double-neg95.8%
unsub-neg95.8%
div-sub95.8%
*-inverses95.8%
metadata-eval95.8%
associate--r-95.8%
neg-sub095.8%
distribute-frac-neg295.8%
remove-double-neg95.8%
sub-neg95.8%
Simplified95.8%
sub-neg95.8%
metadata-eval95.8%
distribute-rgt-in95.8%
*-commutative95.8%
*-un-lft-identity95.8%
Applied egg-rr95.8%
Taylor expanded in x around 0 92.2%
associate-*l/93.5%
associate-/r/96.7%
Simplified96.7%
Final simplification96.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.8e-31) (not (<= y 1.6e-66))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-31) || !(y <= 1.6e-66)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
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 ((y <= (-4.8d-31)) .or. (.not. (y <= 1.6d-66))) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.8e-31) || !(y <= 1.6e-66)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.8e-31) or not (y <= 1.6e-66): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.8e-31) || !(y <= 1.6e-66)) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.8e-31) || ~((y <= 1.6e-66))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.8e-31], N[Not[LessEqual[y, 1.6e-66]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-31} \lor \neg \left(y \leq 1.6 \cdot 10^{-66}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.8e-31 or 1.59999999999999991e-66 < y Initial program 86.8%
associate-/l*93.0%
remove-double-neg93.0%
distribute-frac-neg293.0%
neg-sub093.0%
remove-double-neg93.0%
unsub-neg93.0%
div-sub93.0%
*-inverses93.0%
metadata-eval93.0%
associate--r-93.0%
neg-sub093.0%
distribute-frac-neg293.0%
remove-double-neg93.0%
sub-neg93.0%
Simplified93.0%
Taylor expanded in y around inf 67.2%
*-commutative67.2%
associate-/l*70.9%
Applied egg-rr70.9%
if -4.8e-31 < y < 1.59999999999999991e-66Initial program 76.5%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
*-inverses99.8%
metadata-eval99.8%
associate--r-99.8%
neg-sub099.8%
distribute-frac-neg299.8%
remove-double-neg99.8%
sub-neg99.8%
Simplified99.8%
Taylor expanded in y around 0 78.9%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e-28) (* y (/ x z)) (if (<= y 4.8e-65) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e-28) {
tmp = y * (x / z);
} else if (y <= 4.8e-65) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
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 (y <= (-1.7d-28)) then
tmp = y * (x / z)
else if (y <= 4.8d-65) then
tmp = x
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e-28) {
tmp = y * (x / z);
} else if (y <= 4.8e-65) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e-28: tmp = y * (x / z) elif y <= 4.8e-65: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e-28) tmp = Float64(y * Float64(x / z)); elseif (y <= 4.8e-65) tmp = x; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.7e-28) tmp = y * (x / z); elseif (y <= 4.8e-65) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e-28], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.8e-65], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-28}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-65}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.7e-28Initial program 90.1%
associate-/l*91.4%
remove-double-neg91.4%
distribute-frac-neg291.4%
neg-sub091.4%
remove-double-neg91.4%
unsub-neg91.4%
div-sub91.4%
*-inverses91.4%
metadata-eval91.4%
associate--r-91.4%
neg-sub091.4%
distribute-frac-neg291.4%
remove-double-neg91.4%
sub-neg91.4%
Simplified91.4%
Taylor expanded in y around inf 70.7%
*-commutative70.7%
associate-/l*73.2%
Applied egg-rr73.2%
if -1.7e-28 < y < 4.8000000000000003e-65Initial program 76.5%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
*-inverses99.8%
metadata-eval99.8%
associate--r-99.8%
neg-sub099.8%
distribute-frac-neg299.8%
remove-double-neg99.8%
sub-neg99.8%
Simplified99.8%
Taylor expanded in y around 0 78.9%
if 4.8000000000000003e-65 < y Initial program 84.2%
associate-/l*94.3%
remove-double-neg94.3%
distribute-frac-neg294.3%
neg-sub094.3%
remove-double-neg94.3%
unsub-neg94.3%
div-sub94.3%
*-inverses94.3%
metadata-eval94.3%
associate--r-94.3%
neg-sub094.3%
distribute-frac-neg294.3%
remove-double-neg94.3%
sub-neg94.3%
Simplified94.3%
Taylor expanded in y around inf 64.4%
*-commutative64.4%
associate-/l*69.2%
Applied egg-rr69.2%
clear-num69.1%
un-div-inv69.7%
Applied egg-rr69.7%
(FPCore (x y z) :precision binary64 (if (<= z -8.4e-57) x (if (<= z 5e+68) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.4e-57) {
tmp = x;
} else if (z <= 5e+68) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
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 <= (-8.4d-57)) then
tmp = x
else if (z <= 5d+68) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8.4e-57) {
tmp = x;
} else if (z <= 5e+68) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.4e-57: tmp = x elif z <= 5e+68: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.4e-57) tmp = x; elseif (z <= 5e+68) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.4e-57) tmp = x; elseif (z <= 5e+68) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.4e-57], x, If[LessEqual[z, 5e+68], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.4 \cdot 10^{-57}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+68}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.3999999999999998e-57 or 5.0000000000000004e68 < z Initial program 74.5%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 74.0%
if -8.3999999999999998e-57 < z < 5.0000000000000004e68Initial program 90.9%
associate-/l*91.6%
remove-double-neg91.6%
distribute-frac-neg291.6%
neg-sub091.6%
remove-double-neg91.6%
unsub-neg91.6%
div-sub91.6%
*-inverses91.6%
metadata-eval91.6%
associate--r-91.6%
neg-sub091.6%
distribute-frac-neg291.6%
remove-double-neg91.6%
sub-neg91.6%
Simplified91.6%
Taylor expanded in y around inf 73.4%
associate-*r/69.4%
Simplified69.4%
(FPCore (x y z) :precision binary64 (* x (- (/ y z) -1.0)))
double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * ((y / z) - (-1.0d0))
end function
public static double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
def code(x, y, z): return x * ((y / z) - -1.0)
function code(x, y, z) return Float64(x * Float64(Float64(y / z) - -1.0)) end
function tmp = code(x, y, z) tmp = x * ((y / z) - -1.0); end
code[x_, y_, z_] := N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{z} - -1\right)
\end{array}
Initial program 82.6%
associate-/l*95.8%
remove-double-neg95.8%
distribute-frac-neg295.8%
neg-sub095.8%
remove-double-neg95.8%
unsub-neg95.8%
div-sub95.8%
*-inverses95.8%
metadata-eval95.8%
associate--r-95.8%
neg-sub095.8%
distribute-frac-neg295.8%
remove-double-neg95.8%
sub-neg95.8%
Simplified95.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 82.6%
associate-/l*95.8%
remove-double-neg95.8%
distribute-frac-neg295.8%
neg-sub095.8%
remove-double-neg95.8%
unsub-neg95.8%
div-sub95.8%
*-inverses95.8%
metadata-eval95.8%
associate--r-95.8%
neg-sub095.8%
distribute-frac-neg295.8%
remove-double-neg95.8%
sub-neg95.8%
Simplified95.8%
Taylor expanded in y around 0 48.4%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (y + z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2024087
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))