
(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.6%
associate-*l/83.3%
remove-double-neg83.3%
unsub-neg83.3%
distribute-rgt-out--77.8%
*-commutative77.8%
remove-double-neg77.8%
distribute-frac-neg277.8%
distribute-frac-neg77.8%
associate-*l/83.1%
associate-/l*94.8%
*-inverses94.8%
*-rgt-identity94.8%
associate-*r/93.4%
*-commutative93.4%
associate-*r/96.9%
fma-neg96.9%
remove-double-neg96.9%
Simplified96.9%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (<= z -3.75e+93) x (if (<= z 1.22e+60) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.75e+93) {
tmp = x;
} else if (z <= 1.22e+60) {
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 <= (-3.75d+93)) then
tmp = x
else if (z <= 1.22d+60) 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 <= -3.75e+93) {
tmp = x;
} else if (z <= 1.22e+60) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.75e+93: tmp = x elif z <= 1.22e+60: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.75e+93) tmp = x; elseif (z <= 1.22e+60) 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 <= -3.75e+93) tmp = x; elseif (z <= 1.22e+60) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.75e+93], x, If[LessEqual[z, 1.22e+60], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.75 \cdot 10^{+93}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.22 \cdot 10^{+60}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.7500000000000001e93 or 1.21999999999999995e60 < z Initial program 66.9%
associate-/l*100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-inverses100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
distribute-lft-in100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-in100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 81.6%
if -3.7500000000000001e93 < z < 1.21999999999999995e60Initial program 94.8%
associate-/l*95.2%
remove-double-neg95.2%
distribute-lft-neg-in95.2%
distribute-rgt-neg-in95.2%
distribute-frac-neg295.2%
remove-double-neg95.2%
unsub-neg95.2%
div-sub95.2%
*-inverses95.2%
metadata-eval95.2%
sub-neg95.2%
metadata-eval95.2%
metadata-eval95.2%
distribute-lft-in95.2%
distribute-lft-neg-out95.2%
distribute-rgt-neg-out95.2%
distribute-frac-neg295.2%
remove-double-neg95.2%
distribute-lft-neg-in95.2%
distribute-rgt-neg-in95.2%
distribute-lft-in95.2%
sub-neg95.2%
Simplified95.2%
Taylor expanded in y around inf 72.9%
associate-*r/72.7%
Simplified72.7%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.55e+94) x (if (<= z 2.9e+60) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e+94) {
tmp = x;
} else if (z <= 2.9e+60) {
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.55d+94)) then
tmp = x
else if (z <= 2.9d+60) 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.55e+94) {
tmp = x;
} else if (z <= 2.9e+60) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.55e+94: tmp = x elif z <= 2.9e+60: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.55e+94) tmp = x; elseif (z <= 2.9e+60) 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.55e+94) tmp = x; elseif (z <= 2.9e+60) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.55e+94], x, If[LessEqual[z, 2.9e+60], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+94}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+60}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.54999999999999996e94 or 2.9e60 < z Initial program 66.9%
associate-/l*100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-inverses100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
distribute-lft-in100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-in100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 81.6%
if -1.54999999999999996e94 < z < 2.9e60Initial program 94.8%
associate-/l*95.2%
remove-double-neg95.2%
distribute-lft-neg-in95.2%
distribute-rgt-neg-in95.2%
distribute-frac-neg295.2%
remove-double-neg95.2%
unsub-neg95.2%
div-sub95.2%
*-inverses95.2%
metadata-eval95.2%
sub-neg95.2%
metadata-eval95.2%
metadata-eval95.2%
distribute-lft-in95.2%
distribute-lft-neg-out95.2%
distribute-rgt-neg-out95.2%
distribute-frac-neg295.2%
remove-double-neg95.2%
distribute-lft-neg-in95.2%
distribute-rgt-neg-in95.2%
distribute-lft-in95.2%
sub-neg95.2%
Simplified95.2%
Taylor expanded in y around inf 72.9%
*-commutative72.9%
associate-/l*74.9%
Applied egg-rr74.9%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e+117) (* y (/ x z)) (if (<= y 6e-34) x (/ (* x y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+117) {
tmp = y * (x / z);
} else if (y <= 6e-34) {
tmp = x;
} else {
tmp = (x * y) / z;
}
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 <= (-3.8d+117)) then
tmp = y * (x / z)
else if (y <= 6d-34) then
tmp = x
else
tmp = (x * y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+117) {
tmp = y * (x / z);
} else if (y <= 6e-34) {
tmp = x;
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e+117: tmp = y * (x / z) elif y <= 6e-34: tmp = x else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+117) tmp = Float64(y * Float64(x / z)); elseif (y <= 6e-34) tmp = x; else tmp = Float64(Float64(x * y) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e+117) tmp = y * (x / z); elseif (y <= 6e-34) tmp = x; else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+117], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6e-34], x, N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+117}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if y < -3.8000000000000002e117Initial program 89.0%
associate-/l*92.7%
remove-double-neg92.7%
distribute-lft-neg-in92.7%
distribute-rgt-neg-in92.7%
distribute-frac-neg292.7%
remove-double-neg92.7%
unsub-neg92.7%
div-sub92.7%
*-inverses92.7%
metadata-eval92.7%
sub-neg92.7%
metadata-eval92.7%
metadata-eval92.7%
distribute-lft-in92.7%
distribute-lft-neg-out92.7%
distribute-rgt-neg-out92.7%
distribute-frac-neg292.7%
remove-double-neg92.7%
distribute-lft-neg-in92.7%
distribute-rgt-neg-in92.7%
distribute-lft-in92.7%
sub-neg92.7%
Simplified92.7%
Taylor expanded in y around inf 83.4%
*-commutative83.4%
associate-/l*89.6%
Applied egg-rr89.6%
if -3.8000000000000002e117 < y < 6e-34Initial program 80.7%
associate-/l*99.9%
remove-double-neg99.9%
distribute-lft-neg-in99.9%
distribute-rgt-neg-in99.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
sub-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
distribute-lft-in99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-out99.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
distribute-lft-neg-in99.9%
distribute-rgt-neg-in99.9%
distribute-lft-in99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 72.1%
if 6e-34 < y Initial program 88.3%
associate-/l*94.8%
remove-double-neg94.8%
distribute-lft-neg-in94.8%
distribute-rgt-neg-in94.8%
distribute-frac-neg294.8%
remove-double-neg94.8%
unsub-neg94.8%
div-sub94.8%
*-inverses94.8%
metadata-eval94.8%
sub-neg94.8%
metadata-eval94.8%
metadata-eval94.8%
distribute-lft-in94.8%
distribute-lft-neg-out94.8%
distribute-rgt-neg-out94.8%
distribute-frac-neg294.8%
remove-double-neg94.8%
distribute-lft-neg-in94.8%
distribute-rgt-neg-in94.8%
distribute-lft-in94.8%
sub-neg94.8%
Simplified94.8%
Taylor expanded in y around inf 78.3%
Final simplification77.5%
(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.6%
associate-/l*96.9%
remove-double-neg96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
distribute-frac-neg296.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub96.9%
*-inverses96.9%
metadata-eval96.9%
sub-neg96.9%
metadata-eval96.9%
metadata-eval96.9%
distribute-lft-in96.9%
distribute-lft-neg-out96.9%
distribute-rgt-neg-out96.9%
distribute-frac-neg296.9%
remove-double-neg96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
distribute-lft-in96.9%
sub-neg96.9%
Simplified96.9%
Final simplification96.9%
(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.6%
associate-/l*96.9%
remove-double-neg96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
distribute-frac-neg296.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub96.9%
*-inverses96.9%
metadata-eval96.9%
sub-neg96.9%
metadata-eval96.9%
metadata-eval96.9%
distribute-lft-in96.9%
distribute-lft-neg-out96.9%
distribute-rgt-neg-out96.9%
distribute-frac-neg296.9%
remove-double-neg96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
distribute-lft-in96.9%
sub-neg96.9%
Simplified96.9%
Taylor expanded in y around 0 45.2%
Final simplification45.2%
(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 2024046
(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))