
(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.4%
remove-double-neg84.4%
distribute-frac-neg284.4%
distribute-frac-neg84.4%
distribute-rgt-neg-in84.4%
distribute-neg-in84.4%
distribute-lft-out83.8%
*-commutative83.8%
cancel-sign-sub-inv83.8%
div-sub83.9%
associate-*r/83.1%
distribute-neg-frac83.1%
distribute-frac-neg283.1%
remove-double-neg83.1%
fma-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
*-commutative83.1%
associate-/l*96.6%
*-inverses96.6%
*-rgt-identity96.6%
Simplified96.6%
Final simplification96.6%
(FPCore (x y z)
:precision binary64
(if (<= z -2.4e+22)
x
(if (or (<= z -5.6e-22) (and (not (<= z -2.7e-66)) (<= z 4.1e+79)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+22) {
tmp = x;
} else if ((z <= -5.6e-22) || (!(z <= -2.7e-66) && (z <= 4.1e+79))) {
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 <= (-2.4d+22)) then
tmp = x
else if ((z <= (-5.6d-22)) .or. (.not. (z <= (-2.7d-66))) .and. (z <= 4.1d+79)) 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 <= -2.4e+22) {
tmp = x;
} else if ((z <= -5.6e-22) || (!(z <= -2.7e-66) && (z <= 4.1e+79))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e+22: tmp = x elif (z <= -5.6e-22) or (not (z <= -2.7e-66) and (z <= 4.1e+79)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e+22) tmp = x; elseif ((z <= -5.6e-22) || (!(z <= -2.7e-66) && (z <= 4.1e+79))) 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 <= -2.4e+22) tmp = x; elseif ((z <= -5.6e-22) || (~((z <= -2.7e-66)) && (z <= 4.1e+79))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+22], x, If[Or[LessEqual[z, -5.6e-22], And[N[Not[LessEqual[z, -2.7e-66]], $MachinePrecision], LessEqual[z, 4.1e+79]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.6 \cdot 10^{-22} \lor \neg \left(z \leq -2.7 \cdot 10^{-66}\right) \land z \leq 4.1 \cdot 10^{+79}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.4e22 or -5.5999999999999999e-22 < z < -2.69999999999999996e-66 or 4.1e79 < z Initial program 74.7%
associate-/l*99.2%
remove-double-neg99.2%
distribute-frac-neg299.2%
neg-sub099.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub99.2%
*-inverses99.2%
metadata-eval99.2%
associate--r-99.2%
neg-sub099.2%
distribute-frac-neg299.2%
remove-double-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 87.1%
if -2.4e22 < z < -5.5999999999999999e-22 or -2.69999999999999996e-66 < z < 4.1e79Initial program 93.4%
associate-/l*94.2%
remove-double-neg94.2%
distribute-frac-neg294.2%
neg-sub094.2%
remove-double-neg94.2%
unsub-neg94.2%
div-sub94.2%
*-inverses94.2%
metadata-eval94.2%
associate--r-94.2%
neg-sub094.2%
distribute-frac-neg294.2%
remove-double-neg94.2%
sub-neg94.2%
Simplified94.2%
Taylor expanded in y around inf 74.7%
associate-*r/72.3%
Simplified72.3%
Final simplification79.4%
(FPCore (x y z)
:precision binary64
(if (<= z -2.4e+25)
x
(if (<= z -6e-22)
(* x (/ y z))
(if (<= z -2.15e-66) x (if (<= z 4.1e+79) (* y (/ x z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+25) {
tmp = x;
} else if (z <= -6e-22) {
tmp = x * (y / z);
} else if (z <= -2.15e-66) {
tmp = x;
} else if (z <= 4.1e+79) {
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 <= (-2.4d+25)) then
tmp = x
else if (z <= (-6d-22)) then
tmp = x * (y / z)
else if (z <= (-2.15d-66)) then
tmp = x
else if (z <= 4.1d+79) 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 <= -2.4e+25) {
tmp = x;
} else if (z <= -6e-22) {
tmp = x * (y / z);
} else if (z <= -2.15e-66) {
tmp = x;
} else if (z <= 4.1e+79) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e+25: tmp = x elif z <= -6e-22: tmp = x * (y / z) elif z <= -2.15e-66: tmp = x elif z <= 4.1e+79: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e+25) tmp = x; elseif (z <= -6e-22) tmp = Float64(x * Float64(y / z)); elseif (z <= -2.15e-66) tmp = x; elseif (z <= 4.1e+79) 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 <= -2.4e+25) tmp = x; elseif (z <= -6e-22) tmp = x * (y / z); elseif (z <= -2.15e-66) tmp = x; elseif (z <= 4.1e+79) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+25], x, If[LessEqual[z, -6e-22], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -2.15e-66], x, If[LessEqual[z, 4.1e+79], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6 \cdot 10^{-22}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;z \leq -2.15 \cdot 10^{-66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{+79}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.39999999999999996e25 or -5.9999999999999998e-22 < z < -2.15000000000000007e-66 or 4.1e79 < z Initial program 74.7%
associate-/l*99.2%
remove-double-neg99.2%
distribute-frac-neg299.2%
neg-sub099.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub99.2%
*-inverses99.2%
metadata-eval99.2%
associate--r-99.2%
neg-sub099.2%
distribute-frac-neg299.2%
remove-double-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 87.1%
if -2.39999999999999996e25 < z < -5.9999999999999998e-22Initial program 100.0%
associate-/l*100.0%
remove-double-neg100.0%
distribute-frac-neg2100.0%
neg-sub0100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-inverses100.0%
metadata-eval100.0%
associate--r-100.0%
neg-sub0100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 90.3%
associate-*r/90.3%
Simplified90.3%
if -2.15000000000000007e-66 < z < 4.1e79Initial program 92.9%
associate-/l*93.7%
remove-double-neg93.7%
distribute-frac-neg293.7%
neg-sub093.7%
remove-double-neg93.7%
unsub-neg93.7%
div-sub93.7%
*-inverses93.7%
metadata-eval93.7%
associate--r-93.7%
neg-sub093.7%
distribute-frac-neg293.7%
remove-double-neg93.7%
sub-neg93.7%
Simplified93.7%
Taylor expanded in y around inf 73.4%
associate-*l/72.6%
*-commutative72.6%
Simplified72.6%
Final simplification80.3%
(FPCore (x y z)
:precision binary64
(if (<= z -1.25e+22)
x
(if (<= z -4.1e-22)
(* x (/ y z))
(if (<= z -2.4e-66) x (if (<= z 4.6e+79) (/ (* x y) z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e+22) {
tmp = x;
} else if (z <= -4.1e-22) {
tmp = x * (y / z);
} else if (z <= -2.4e-66) {
tmp = x;
} else if (z <= 4.6e+79) {
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+22)) then
tmp = x
else if (z <= (-4.1d-22)) then
tmp = x * (y / z)
else if (z <= (-2.4d-66)) then
tmp = x
else if (z <= 4.6d+79) 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+22) {
tmp = x;
} else if (z <= -4.1e-22) {
tmp = x * (y / z);
} else if (z <= -2.4e-66) {
tmp = x;
} else if (z <= 4.6e+79) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e+22: tmp = x elif z <= -4.1e-22: tmp = x * (y / z) elif z <= -2.4e-66: tmp = x elif z <= 4.6e+79: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e+22) tmp = x; elseif (z <= -4.1e-22) tmp = Float64(x * Float64(y / z)); elseif (z <= -2.4e-66) tmp = x; elseif (z <= 4.6e+79) 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 <= -1.25e+22) tmp = x; elseif (z <= -4.1e-22) tmp = x * (y / z); elseif (z <= -2.4e-66) tmp = x; elseif (z <= 4.6e+79) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e+22], x, If[LessEqual[z, -4.1e-22], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -2.4e-66], x, If[LessEqual[z, 4.6e+79], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.1 \cdot 10^{-22}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{-66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{+79}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.2499999999999999e22 or -4.0999999999999999e-22 < z < -2.40000000000000026e-66 or 4.6000000000000001e79 < z Initial program 74.7%
associate-/l*99.2%
remove-double-neg99.2%
distribute-frac-neg299.2%
neg-sub099.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub99.2%
*-inverses99.2%
metadata-eval99.2%
associate--r-99.2%
neg-sub099.2%
distribute-frac-neg299.2%
remove-double-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 87.1%
if -1.2499999999999999e22 < z < -4.0999999999999999e-22Initial program 100.0%
associate-/l*100.0%
remove-double-neg100.0%
distribute-frac-neg2100.0%
neg-sub0100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-inverses100.0%
metadata-eval100.0%
associate--r-100.0%
neg-sub0100.0%
distribute-frac-neg2100.0%
remove-double-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 90.3%
associate-*r/90.3%
Simplified90.3%
if -2.40000000000000026e-66 < z < 4.6000000000000001e79Initial program 92.9%
associate-/l*93.7%
remove-double-neg93.7%
distribute-frac-neg293.7%
neg-sub093.7%
remove-double-neg93.7%
unsub-neg93.7%
div-sub93.7%
*-inverses93.7%
metadata-eval93.7%
associate--r-93.7%
neg-sub093.7%
distribute-frac-neg293.7%
remove-double-neg93.7%
sub-neg93.7%
Simplified93.7%
Taylor expanded in y around inf 73.4%
Final simplification80.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.4%
associate-/l*96.6%
remove-double-neg96.6%
distribute-frac-neg296.6%
neg-sub096.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub96.6%
*-inverses96.6%
metadata-eval96.6%
associate--r-96.6%
neg-sub096.6%
distribute-frac-neg296.6%
remove-double-neg96.6%
sub-neg96.6%
Simplified96.6%
Final simplification96.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.4%
associate-/l*96.6%
remove-double-neg96.6%
distribute-frac-neg296.6%
neg-sub096.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub96.6%
*-inverses96.6%
metadata-eval96.6%
associate--r-96.6%
neg-sub096.6%
distribute-frac-neg296.6%
remove-double-neg96.6%
sub-neg96.6%
Simplified96.6%
Taylor expanded in y around 0 54.5%
Final simplification54.5%
(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 2024043
(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))