
(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 84.5%
remove-double-neg84.5%
distribute-frac-neg284.5%
distribute-frac-neg84.5%
distribute-rgt-neg-in84.5%
distribute-neg-in84.5%
distribute-lft-out83.8%
*-commutative83.8%
cancel-sign-sub-inv83.8%
div-sub83.8%
associate-*r/81.7%
distribute-neg-frac81.7%
distribute-frac-neg281.7%
remove-double-neg81.7%
fma-neg81.7%
distribute-frac-neg81.7%
distribute-lft-neg-out81.7%
*-commutative81.7%
associate-/l*95.5%
*-inverses95.5%
*-rgt-identity95.5%
Simplified95.5%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.25e+71) x (if (<= z 1.4e+39) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+71) {
tmp = x;
} else if (z <= 1.4e+39) {
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.25d+71)) then
tmp = x
else if (z <= 1.4d+39) 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.25e+71) {
tmp = x;
} else if (z <= 1.4e+39) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+71: tmp = x elif z <= 1.4e+39: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+71) tmp = x; elseif (z <= 1.4e+39) 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.25e+71) tmp = x; elseif (z <= 1.4e+39) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+71], x, If[LessEqual[z, 1.4e+39], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+71}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+39}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.24999999999999993e71 or 1.40000000000000001e39 < z Initial program 74.4%
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 80.4%
if -1.24999999999999993e71 < z < 1.40000000000000001e39Initial program 92.9%
associate-/l*91.8%
remove-double-neg91.8%
distribute-frac-neg291.8%
neg-sub091.8%
remove-double-neg91.8%
unsub-neg91.8%
div-sub91.8%
*-inverses91.8%
metadata-eval91.8%
associate--r-91.8%
neg-sub091.8%
distribute-frac-neg291.8%
remove-double-neg91.8%
sub-neg91.8%
Simplified91.8%
Taylor expanded in y around inf 73.1%
associate-*r/68.2%
Simplified68.2%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.25e+35) x (if (<= z 6.8e+37) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+35) {
tmp = x;
} else if (z <= 6.8e+37) {
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 <= (-1.25d+35)) then
tmp = x
else if (z <= 6.8d+37) 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 <= -1.25e+35) {
tmp = x;
} else if (z <= 6.8e+37) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+35: tmp = x elif z <= 6.8e+37: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+35) tmp = x; elseif (z <= 6.8e+37) 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 <= -1.25e+35) tmp = x; elseif (z <= 6.8e+37) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+35], x, If[LessEqual[z, 6.8e+37], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+35}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+37}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.25000000000000005e35 or 6.80000000000000011e37 < z Initial program 75.2%
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 78.9%
if -1.25000000000000005e35 < z < 6.80000000000000011e37Initial program 92.7%
associate-/l*91.5%
remove-double-neg91.5%
distribute-frac-neg291.5%
neg-sub091.5%
remove-double-neg91.5%
unsub-neg91.5%
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.6%
associate-*l/73.5%
*-commutative73.5%
Simplified73.5%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z -6.2e+35) x (if (<= z 4.3e+39) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.2e+35) {
tmp = x;
} else if (z <= 4.3e+39) {
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 <= (-6.2d+35)) then
tmp = x
else if (z <= 4.3d+39) 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 <= -6.2e+35) {
tmp = x;
} else if (z <= 4.3e+39) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.2e+35: tmp = x elif z <= 4.3e+39: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.2e+35) tmp = x; elseif (z <= 4.3e+39) 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 <= -6.2e+35) tmp = x; elseif (z <= 4.3e+39) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.2e+35], x, If[LessEqual[z, 4.3e+39], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+35}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{+39}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.19999999999999973e35 or 4.3e39 < z Initial program 75.2%
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 78.9%
if -6.19999999999999973e35 < z < 4.3e39Initial program 92.7%
*-commutative92.7%
associate-/l*93.8%
Simplified93.8%
clear-num93.7%
un-div-inv94.7%
Applied egg-rr94.7%
Taylor expanded in y around inf 73.6%
associate-/l*68.6%
*-commutative68.6%
associate-/r/73.9%
Simplified73.9%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= z -8e+66) x (if (<= z 1.8e+39) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e+66) {
tmp = x;
} else if (z <= 1.8e+39) {
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 <= (-8d+66)) then
tmp = x
else if (z <= 1.8d+39) 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 <= -8e+66) {
tmp = x;
} else if (z <= 1.8e+39) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e+66: tmp = x elif z <= 1.8e+39: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e+66) tmp = x; elseif (z <= 1.8e+39) 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 <= -8e+66) tmp = x; elseif (z <= 1.8e+39) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e+66], x, If[LessEqual[z, 1.8e+39], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+39}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.99999999999999956e66 or 1.79999999999999992e39 < z Initial program 74.4%
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 80.4%
if -7.99999999999999956e66 < z < 1.79999999999999992e39Initial program 92.9%
associate-/l*91.8%
remove-double-neg91.8%
distribute-frac-neg291.8%
neg-sub091.8%
remove-double-neg91.8%
unsub-neg91.8%
div-sub91.8%
*-inverses91.8%
metadata-eval91.8%
associate--r-91.8%
neg-sub091.8%
distribute-frac-neg291.8%
remove-double-neg91.8%
sub-neg91.8%
Simplified91.8%
Taylor expanded in y around inf 73.1%
Final simplification76.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 84.5%
associate-/l*95.4%
remove-double-neg95.4%
distribute-frac-neg295.4%
neg-sub095.4%
remove-double-neg95.4%
unsub-neg95.4%
div-sub95.5%
*-inverses95.5%
metadata-eval95.5%
associate--r-95.5%
neg-sub095.5%
distribute-frac-neg295.5%
remove-double-neg95.5%
sub-neg95.5%
Simplified95.5%
Final simplification95.5%
(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.5%
associate-/l*95.4%
remove-double-neg95.4%
distribute-frac-neg295.4%
neg-sub095.4%
remove-double-neg95.4%
unsub-neg95.4%
div-sub95.5%
*-inverses95.5%
metadata-eval95.5%
associate--r-95.5%
neg-sub095.5%
distribute-frac-neg295.5%
remove-double-neg95.5%
sub-neg95.5%
Simplified95.5%
Taylor expanded in y around 0 49.8%
Final simplification49.8%
(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 2024066
(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))