
(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 81.2%
associate-/l*96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
neg-sub096.5%
remove-double-neg96.5%
unsub-neg96.5%
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%
(FPCore (x y z) :precision binary64 (if (<= z -1.3e+115) x (if (<= z 8.4e-299) (* x (/ y z)) (if (<= z 2.7e-112) (* y (/ x z)) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.3e+115) {
tmp = x;
} else if (z <= 8.4e-299) {
tmp = x * (y / z);
} else if (z <= 2.7e-112) {
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.3d+115)) then
tmp = x
else if (z <= 8.4d-299) then
tmp = x * (y / z)
else if (z <= 2.7d-112) 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.3e+115) {
tmp = x;
} else if (z <= 8.4e-299) {
tmp = x * (y / z);
} else if (z <= 2.7e-112) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.3e+115: tmp = x elif z <= 8.4e-299: tmp = x * (y / z) elif z <= 2.7e-112: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.3e+115) tmp = x; elseif (z <= 8.4e-299) tmp = Float64(x * Float64(y / z)); elseif (z <= 2.7e-112) 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.3e+115) tmp = x; elseif (z <= 8.4e-299) tmp = x * (y / z); elseif (z <= 2.7e-112) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.3e+115], x, If[LessEqual[z, 8.4e-299], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.7e-112], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+115}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.4 \cdot 10^{-299}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-112}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3e115 or 2.7000000000000001e-112 < z Initial program 73.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.5%
if -1.3e115 < z < 8.40000000000000041e-299Initial program 89.9%
associate-/l*96.4%
remove-double-neg96.4%
distribute-frac-neg296.4%
neg-sub096.4%
remove-double-neg96.4%
unsub-neg96.4%
div-sub96.5%
*-inverses96.5%
metadata-eval96.5%
associate--r-96.5%
neg-sub096.5%
distribute-frac-neg296.5%
remove-double-neg96.5%
sub-neg96.5%
Simplified96.5%
Taylor expanded in y around inf 74.8%
if 8.40000000000000041e-299 < z < 2.7000000000000001e-112Initial program 88.9%
associate-/l*83.4%
remove-double-neg83.4%
distribute-frac-neg283.4%
neg-sub083.4%
remove-double-neg83.4%
unsub-neg83.4%
div-sub83.4%
*-inverses83.4%
metadata-eval83.4%
associate--r-83.4%
neg-sub083.4%
distribute-frac-neg283.4%
remove-double-neg83.4%
sub-neg83.4%
Simplified83.4%
Taylor expanded in y around inf 81.5%
associate-*l/84.3%
*-commutative84.3%
Simplified84.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.45e+115) x (if (<= z 2.7e-112) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e+115) {
tmp = x;
} else if (z <= 2.7e-112) {
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.45d+115)) then
tmp = x
else if (z <= 2.7d-112) 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.45e+115) {
tmp = x;
} else if (z <= 2.7e-112) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.45e+115: tmp = x elif z <= 2.7e-112: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.45e+115) tmp = x; elseif (z <= 2.7e-112) 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.45e+115) tmp = x; elseif (z <= 2.7e-112) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.45e+115], x, If[LessEqual[z, 2.7e-112], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+115}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-112}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.45000000000000002e115 or 2.7000000000000001e-112 < z Initial program 73.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.5%
if -1.45000000000000002e115 < z < 2.7000000000000001e-112Initial program 89.6%
Taylor expanded in y around inf 74.8%
*-commutative74.8%
Simplified74.8%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.26e+60) x (if (<= z 2.7e-112) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.26e+60) {
tmp = x;
} else if (z <= 2.7e-112) {
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 <= (-1.26d+60)) then
tmp = x
else if (z <= 2.7d-112) 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 <= -1.26e+60) {
tmp = x;
} else if (z <= 2.7e-112) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.26e+60: tmp = x elif z <= 2.7e-112: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.26e+60) tmp = x; elseif (z <= 2.7e-112) 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 <= -1.26e+60) tmp = x; elseif (z <= 2.7e-112) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.26e+60], x, If[LessEqual[z, 2.7e-112], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{+60}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-112}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.26e60 or 2.7000000000000001e-112 < z Initial program 75.1%
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 73.0%
if -1.26e60 < z < 2.7000000000000001e-112Initial program 89.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 77.5%
associate-*l/77.1%
*-commutative77.1%
Simplified77.1%
clear-num77.0%
un-div-inv77.8%
Applied egg-rr77.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+115) x (if (<= z 2.2e-113) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+115) {
tmp = x;
} else if (z <= 2.2e-113) {
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.2d+115)) then
tmp = x
else if (z <= 2.2d-113) 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.2e+115) {
tmp = x;
} else if (z <= 2.2e-113) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+115: tmp = x elif z <= 2.2e-113: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+115) tmp = x; elseif (z <= 2.2e-113) 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.2e+115) tmp = x; elseif (z <= 2.2e-113) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+115], x, If[LessEqual[z, 2.2e-113], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+115}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-113}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2e115 or 2.20000000000000004e-113 < z Initial program 73.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.5%
if -2.2e115 < z < 2.20000000000000004e-113Initial program 89.6%
associate-/l*92.8%
remove-double-neg92.8%
distribute-frac-neg292.8%
neg-sub092.8%
remove-double-neg92.8%
unsub-neg92.8%
div-sub92.8%
*-inverses92.8%
metadata-eval92.8%
associate--r-92.8%
neg-sub092.8%
distribute-frac-neg292.8%
remove-double-neg92.8%
sub-neg92.8%
Simplified92.8%
Taylor expanded in y around inf 72.8%
(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 81.2%
associate-/l*96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
neg-sub096.5%
remove-double-neg96.5%
unsub-neg96.5%
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 50.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 2024144
(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))