
(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 7 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 83.8%
associate-*l/86.0%
distribute-lft-in81.1%
associate-*l/76.2%
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/84.1%
associate-/l*97.3%
*-inverses97.3%
*-rgt-identity97.3%
Simplified97.3%
(FPCore (x y z) :precision binary64 (if (<= z -4.2e+22) x (if (<= z 2.2e-77) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+22) {
tmp = x;
} else if (z <= 2.2e-77) {
tmp = y / (z / x);
} 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 <= (-4.2d+22)) then
tmp = x
else if (z <= 2.2d-77) then
tmp = y / (z / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+22) {
tmp = x;
} else if (z <= 2.2e-77) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e+22: tmp = x elif z <= 2.2e-77: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e+22) tmp = x; elseif (z <= 2.2e-77) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e+22) tmp = x; elseif (z <= 2.2e-77) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e+22], x, If[LessEqual[z, 2.2e-77], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.1999999999999996e22 or 2.20000000000000007e-77 < z Initial program 75.6%
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.5%
if -4.1999999999999996e22 < z < 2.20000000000000007e-77Initial program 94.0%
Taylor expanded in y around inf 77.8%
*-commutative77.8%
Simplified77.8%
associate-*l/76.2%
Applied egg-rr76.2%
associate-*l/77.8%
associate-*r/79.2%
clear-num79.2%
un-div-inv79.6%
Applied egg-rr79.6%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e+19) x (if (<= z 2.5e-77) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+19) {
tmp = x;
} else if (z <= 2.5e-77) {
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 (z <= (-6.6d+19)) then
tmp = x
else if (z <= 2.5d-77) 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 (z <= -6.6e+19) {
tmp = x;
} else if (z <= 2.5e-77) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e+19: tmp = x elif z <= 2.5e-77: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+19) tmp = x; elseif (z <= 2.5e-77) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e+19) tmp = x; elseif (z <= 2.5e-77) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+19], x, If[LessEqual[z, 2.5e-77], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+19}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-77}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.6e19 or 2.49999999999999982e-77 < z Initial program 75.6%
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.5%
if -6.6e19 < z < 2.49999999999999982e-77Initial program 94.0%
associate-/l*94.0%
remove-double-neg94.0%
unsub-neg94.0%
div-sub94.0%
remove-double-neg94.0%
distribute-frac-neg294.0%
*-inverses94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in y around inf 77.8%
associate-*l/79.2%
*-commutative79.2%
Simplified79.2%
(FPCore (x y z) :precision binary64 (if (<= z -6.1e+22) x (if (<= z 4e-77) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.1e+22) {
tmp = x;
} else if (z <= 4e-77) {
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.1d+22)) then
tmp = x
else if (z <= 4d-77) 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.1e+22) {
tmp = x;
} else if (z <= 4e-77) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.1e+22: tmp = x elif z <= 4e-77: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.1e+22) tmp = x; elseif (z <= 4e-77) 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 <= -6.1e+22) tmp = x; elseif (z <= 4e-77) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.1e+22], x, If[LessEqual[z, 4e-77], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.1 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4 \cdot 10^{-77}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.0999999999999998e22 or 3.9999999999999997e-77 < z Initial program 75.6%
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.5%
if -6.0999999999999998e22 < z < 3.9999999999999997e-77Initial program 94.0%
associate-/l*94.0%
remove-double-neg94.0%
unsub-neg94.0%
div-sub94.0%
remove-double-neg94.0%
distribute-frac-neg294.0%
*-inverses94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in y around inf 76.2%
(FPCore (x y z) :precision binary64 (+ x (* x (/ y z))))
double code(double x, double y, double z) {
return x + (x * (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 + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 83.8%
associate-/l*97.3%
remove-double-neg97.3%
unsub-neg97.3%
div-sub97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
*-inverses97.3%
metadata-eval97.3%
Simplified97.3%
sub-neg97.3%
metadata-eval97.3%
distribute-rgt-in97.3%
*-un-lft-identity97.3%
Applied egg-rr97.3%
Final simplification97.3%
(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 83.8%
associate-/l*97.3%
remove-double-neg97.3%
unsub-neg97.3%
div-sub97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
*-inverses97.3%
metadata-eval97.3%
Simplified97.3%
(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 83.8%
associate-/l*97.3%
remove-double-neg97.3%
unsub-neg97.3%
div-sub97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
*-inverses97.3%
metadata-eval97.3%
Simplified97.3%
Taylor expanded in y around 0 52.1%
(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 2024186
(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))