
(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 (fma x (/ y z) x))
double code(double x, double y, double z) {
return fma(x, (y / z), x);
}
function code(x, y, z) return fma(x, Float64(y / z), x) end
code[x_, y_, z_] := N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
\end{array}
Initial program 84.1%
associate-*l/86.5%
distribute-lft-in82.8%
associate-*l/78.6%
associate-*r/80.4%
fma-undefine80.4%
remove-double-neg80.4%
distribute-rgt-neg-out80.4%
distribute-lft-neg-out80.4%
distribute-frac-neg280.4%
associate-*l/82.6%
associate-/l*96.6%
*-inverses96.6%
*-rgt-identity96.6%
Simplified96.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.4) (not (<= y 7.3e+22))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.4) || !(y <= 7.3e+22)) {
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 <= (-6.4d0)) .or. (.not. (y <= 7.3d+22))) 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 <= -6.4) || !(y <= 7.3e+22)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.4) or not (y <= 7.3e+22): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.4) || !(y <= 7.3e+22)) 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 <= -6.4) || ~((y <= 7.3e+22))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.4], N[Not[LessEqual[y, 7.3e+22]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \lor \neg \left(y \leq 7.3 \cdot 10^{+22}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.4000000000000004 or 7.29999999999999979e22 < y Initial program 90.8%
associate-/l*92.4%
remove-double-neg92.4%
unsub-neg92.4%
div-sub92.4%
remove-double-neg92.4%
distribute-frac-neg292.4%
*-inverses92.4%
metadata-eval92.4%
Simplified92.4%
Taylor expanded in y around inf 71.4%
associate-*l/73.6%
*-commutative73.6%
Simplified73.6%
if -6.4000000000000004 < y < 7.29999999999999979e22Initial program 78.8%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 81.8%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e-36) x (if (<= z 1.2e-68) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e-36) {
tmp = x;
} else if (z <= 1.2e-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 <= (-6.6d-36)) then
tmp = x
else if (z <= 1.2d-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 <= -6.6e-36) {
tmp = x;
} else if (z <= 1.2e-68) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e-36: tmp = x elif z <= 1.2e-68: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e-36) tmp = x; elseif (z <= 1.2e-68) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e-36) tmp = x; elseif (z <= 1.2e-68) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e-36], x, If[LessEqual[z, 1.2e-68], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-68}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.59999999999999981e-36 or 1.19999999999999996e-68 < z Initial program 79.0%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 78.8%
if -6.59999999999999981e-36 < z < 1.19999999999999996e-68Initial program 92.8%
Taylor expanded in y around inf 77.6%
*-commutative77.6%
Simplified77.6%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e-37) x (if (<= z 2.35e-70) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-37) {
tmp = x;
} else if (z <= 2.35e-70) {
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 <= (-1.2d-37)) then
tmp = x
else if (z <= 2.35d-70) 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 <= -1.2e-37) {
tmp = x;
} else if (z <= 2.35e-70) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e-37: tmp = x elif z <= 2.35e-70: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e-37) tmp = x; elseif (z <= 2.35e-70) 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 <= -1.2e-37) tmp = x; elseif (z <= 2.35e-70) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e-37], x, If[LessEqual[z, 2.35e-70], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.35 \cdot 10^{-70}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.19999999999999995e-37 or 2.3499999999999999e-70 < z Initial program 79.0%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 78.8%
if -1.19999999999999995e-37 < z < 2.3499999999999999e-70Initial program 92.8%
associate-/l*91.0%
remove-double-neg91.0%
unsub-neg91.0%
div-sub91.0%
remove-double-neg91.0%
distribute-frac-neg291.0%
*-inverses91.0%
metadata-eval91.0%
Simplified91.0%
Taylor expanded in y around inf 72.7%
(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 84.1%
associate-/l*96.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub96.6%
remove-double-neg96.6%
distribute-frac-neg296.6%
*-inverses96.6%
metadata-eval96.6%
Simplified96.6%
(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 84.1%
associate-/l*96.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub96.6%
remove-double-neg96.6%
distribute-frac-neg296.6%
*-inverses96.6%
metadata-eval96.6%
Simplified96.6%
Taylor expanded in y around 0 57.3%
(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 2024163
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))