
(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 4 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.9%
associate-/l*97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
neg-sub097.7%
remove-double-neg97.7%
unsub-neg97.7%
div-sub97.7%
*-inverses97.7%
metadata-eval97.7%
associate--r-97.7%
neg-sub097.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
sub-neg97.7%
Simplified97.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.25e-114) x (if (<= z 2.1e+127) (/ x (/ z y)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.25e-114) {
tmp = x;
} else if (z <= 2.1e+127) {
tmp = x / (z / y);
} 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.25d-114)) then
tmp = x
else if (z <= 2.1d+127) then
tmp = x / (z / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.25e-114) {
tmp = x;
} else if (z <= 2.1e+127) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.25e-114: tmp = x elif z <= 2.1e+127: tmp = x / (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.25e-114) tmp = x; elseif (z <= 2.1e+127) tmp = Float64(x / Float64(z / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.25e-114) tmp = x; elseif (z <= 2.1e+127) tmp = x / (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.25e-114], x, If[LessEqual[z, 2.1e+127], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+127}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.24999999999999984e-114 or 2.09999999999999992e127 < z Initial program 78.3%
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 0 81.5%
if -2.24999999999999984e-114 < z < 2.09999999999999992e127Initial program 92.0%
associate-/l*95.9%
remove-double-neg95.9%
distribute-frac-neg295.9%
neg-sub095.9%
remove-double-neg95.9%
unsub-neg95.9%
div-sub95.9%
*-inverses95.9%
metadata-eval95.9%
associate--r-95.9%
neg-sub095.9%
distribute-frac-neg295.9%
remove-double-neg95.9%
sub-neg95.9%
Simplified95.9%
Taylor expanded in y around inf 74.4%
clear-num74.3%
un-div-inv74.7%
Applied egg-rr74.7%
(FPCore (x y z) :precision binary64 (if (<= z -7e-115) x (if (<= z 4.8e+123) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e-115) {
tmp = x;
} else if (z <= 4.8e+123) {
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 <= (-7d-115)) then
tmp = x
else if (z <= 4.8d+123) 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 <= -7e-115) {
tmp = x;
} else if (z <= 4.8e+123) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e-115: tmp = x elif z <= 4.8e+123: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e-115) tmp = x; elseif (z <= 4.8e+123) 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 <= -7e-115) tmp = x; elseif (z <= 4.8e+123) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e-115], x, If[LessEqual[z, 4.8e+123], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-115}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+123}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.0000000000000004e-115 or 4.79999999999999978e123 < z Initial program 78.3%
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 0 81.5%
if -7.0000000000000004e-115 < z < 4.79999999999999978e123Initial program 92.0%
associate-/l*95.9%
remove-double-neg95.9%
distribute-frac-neg295.9%
neg-sub095.9%
remove-double-neg95.9%
unsub-neg95.9%
div-sub95.9%
*-inverses95.9%
metadata-eval95.9%
associate--r-95.9%
neg-sub095.9%
distribute-frac-neg295.9%
remove-double-neg95.9%
sub-neg95.9%
Simplified95.9%
Taylor expanded in y around inf 74.4%
(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.9%
associate-/l*97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
neg-sub097.7%
remove-double-neg97.7%
unsub-neg97.7%
div-sub97.7%
*-inverses97.7%
metadata-eval97.7%
associate--r-97.7%
neg-sub097.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
sub-neg97.7%
Simplified97.7%
Taylor expanded in y around 0 49.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 2024135
(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))