
(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 (* 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 85.1%
associate-/l*95.0%
remove-double-neg95.0%
distribute-frac-neg295.0%
neg-sub095.0%
remove-double-neg95.0%
unsub-neg95.0%
div-sub95.0%
*-inverses95.0%
metadata-eval95.0%
associate--r-95.0%
neg-sub095.0%
distribute-frac-neg295.0%
remove-double-neg95.0%
sub-neg95.0%
Simplified95.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.45e-20)
(and (not (<= y -1.8e-141))
(or (<= y -4.7e-147) (not (<= y 2.4e-155)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e-20) || (!(y <= -1.8e-141) && ((y <= -4.7e-147) || !(y <= 2.4e-155)))) {
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 ((y <= (-1.45d-20)) .or. (.not. (y <= (-1.8d-141))) .and. (y <= (-4.7d-147)) .or. (.not. (y <= 2.4d-155))) 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 ((y <= -1.45e-20) || (!(y <= -1.8e-141) && ((y <= -4.7e-147) || !(y <= 2.4e-155)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e-20) or (not (y <= -1.8e-141) and ((y <= -4.7e-147) or not (y <= 2.4e-155))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e-20) || (!(y <= -1.8e-141) && ((y <= -4.7e-147) || !(y <= 2.4e-155)))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.45e-20) || (~((y <= -1.8e-141)) && ((y <= -4.7e-147) || ~((y <= 2.4e-155))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e-20], And[N[Not[LessEqual[y, -1.8e-141]], $MachinePrecision], Or[LessEqual[y, -4.7e-147], N[Not[LessEqual[y, 2.4e-155]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-20} \lor \neg \left(y \leq -1.8 \cdot 10^{-141}\right) \land \left(y \leq -4.7 \cdot 10^{-147} \lor \neg \left(y \leq 2.4 \cdot 10^{-155}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.45e-20 or -1.80000000000000007e-141 < y < -4.69999999999999989e-147 or 2.4e-155 < y Initial program 88.0%
associate-/l*92.3%
remove-double-neg92.3%
distribute-frac-neg292.3%
neg-sub092.3%
remove-double-neg92.3%
unsub-neg92.3%
div-sub92.3%
*-inverses92.3%
metadata-eval92.3%
associate--r-92.3%
neg-sub092.3%
distribute-frac-neg292.3%
remove-double-neg92.3%
sub-neg92.3%
Simplified92.3%
Taylor expanded in y around inf 68.9%
if -1.45e-20 < y < -1.80000000000000007e-141 or -4.69999999999999989e-147 < y < 2.4e-155Initial program 79.9%
associate-/l*100.0%
remove-double-neg100.0%
distribute-frac-neg2100.0%
neg-sub0100.0%
remove-double-neg100.0%
unsub-neg100.0%
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.5%
Final simplification72.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-18) (not (<= y 3.5e-89))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-18) || !(y <= 3.5e-89)) {
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 <= (-1.1d-18)) .or. (.not. (y <= 3.5d-89))) 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 <= -1.1e-18) || !(y <= 3.5e-89)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-18) or not (y <= 3.5e-89): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-18) || !(y <= 3.5e-89)) 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 <= -1.1e-18) || ~((y <= 3.5e-89))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-18], N[Not[LessEqual[y, 3.5e-89]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-18} \lor \neg \left(y \leq 3.5 \cdot 10^{-89}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.0999999999999999e-18 or 3.4999999999999997e-89 < y Initial program 87.7%
associate-/l*91.3%
remove-double-neg91.3%
distribute-frac-neg291.3%
neg-sub091.3%
remove-double-neg91.3%
unsub-neg91.3%
div-sub91.3%
*-inverses91.3%
metadata-eval91.3%
associate--r-91.3%
neg-sub091.3%
distribute-frac-neg291.3%
remove-double-neg91.3%
sub-neg91.3%
Simplified91.3%
Taylor expanded in y around inf 74.4%
associate-*l/73.9%
*-commutative73.9%
Simplified73.9%
if -1.0999999999999999e-18 < y < 3.4999999999999997e-89Initial program 81.8%
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 75.2%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e-17) (* y (/ x z)) (if (<= y 2.4e-155) x (/ (* x y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-17) {
tmp = y * (x / z);
} else if (y <= 2.4e-155) {
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 <= (-5.2d-17)) then
tmp = y * (x / z)
else if (y <= 2.4d-155) 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 <= -5.2e-17) {
tmp = y * (x / z);
} else if (y <= 2.4e-155) {
tmp = x;
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e-17: tmp = y * (x / z) elif y <= 2.4e-155: tmp = x else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-17) tmp = Float64(y * Float64(x / z)); elseif (y <= 2.4e-155) 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 <= -5.2e-17) tmp = y * (x / z); elseif (y <= 2.4e-155) tmp = x; else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-17], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.4e-155], x, N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-17}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-155}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if y < -5.20000000000000006e-17Initial program 83.5%
associate-/l*92.1%
remove-double-neg92.1%
distribute-frac-neg292.1%
neg-sub092.1%
remove-double-neg92.1%
unsub-neg92.1%
div-sub92.1%
*-inverses92.1%
metadata-eval92.1%
associate--r-92.1%
neg-sub092.1%
distribute-frac-neg292.1%
remove-double-neg92.1%
sub-neg92.1%
Simplified92.1%
Taylor expanded in y around inf 74.3%
associate-*l/78.4%
*-commutative78.4%
Simplified78.4%
if -5.20000000000000006e-17 < y < 2.4e-155Initial program 80.8%
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.1%
if 2.4e-155 < y Initial program 91.2%
associate-/l*92.2%
remove-double-neg92.2%
distribute-frac-neg292.2%
neg-sub092.2%
remove-double-neg92.2%
unsub-neg92.2%
div-sub92.2%
*-inverses92.2%
metadata-eval92.2%
associate--r-92.2%
neg-sub092.2%
distribute-frac-neg292.2%
remove-double-neg92.2%
sub-neg92.2%
Simplified92.2%
Taylor expanded in y around inf 68.2%
(FPCore (x y z) :precision binary64 (if (<= y -8e-16) (* y (/ x z)) (if (<= y 1.7e-89) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e-16) {
tmp = y * (x / z);
} else if (y <= 1.7e-89) {
tmp = x;
} else {
tmp = y / (z / 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 <= (-8d-16)) then
tmp = y * (x / z)
else if (y <= 1.7d-89) then
tmp = x
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8e-16) {
tmp = y * (x / z);
} else if (y <= 1.7e-89) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e-16: tmp = y * (x / z) elif y <= 1.7e-89: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e-16) tmp = Float64(y * Float64(x / z)); elseif (y <= 1.7e-89) tmp = x; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e-16) tmp = y * (x / z); elseif (y <= 1.7e-89) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e-16], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.7e-89], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-16}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-89}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -7.9999999999999998e-16Initial program 83.5%
associate-/l*92.1%
remove-double-neg92.1%
distribute-frac-neg292.1%
neg-sub092.1%
remove-double-neg92.1%
unsub-neg92.1%
div-sub92.1%
*-inverses92.1%
metadata-eval92.1%
associate--r-92.1%
neg-sub092.1%
distribute-frac-neg292.1%
remove-double-neg92.1%
sub-neg92.1%
Simplified92.1%
Taylor expanded in y around inf 74.3%
associate-*l/78.4%
*-commutative78.4%
Simplified78.4%
if -7.9999999999999998e-16 < y < 1.7e-89Initial program 81.8%
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 75.2%
if 1.7e-89 < y Initial program 92.0%
associate-/l*90.5%
remove-double-neg90.5%
distribute-frac-neg290.5%
neg-sub090.5%
remove-double-neg90.5%
unsub-neg90.5%
div-sub90.5%
*-inverses90.5%
metadata-eval90.5%
associate--r-90.5%
neg-sub090.5%
distribute-frac-neg290.5%
remove-double-neg90.5%
sub-neg90.5%
Simplified90.5%
Taylor expanded in y around inf 65.3%
associate-*r/74.5%
*-commutative74.5%
associate-*r/69.3%
clear-num69.2%
un-div-inv69.3%
Applied egg-rr69.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 85.1%
associate-/l*95.0%
remove-double-neg95.0%
distribute-frac-neg295.0%
neg-sub095.0%
remove-double-neg95.0%
unsub-neg95.0%
div-sub95.0%
*-inverses95.0%
metadata-eval95.0%
associate--r-95.0%
neg-sub095.0%
distribute-frac-neg295.0%
remove-double-neg95.0%
sub-neg95.0%
Simplified95.0%
Taylor expanded in y around 0 45.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 2024107
(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))