
(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 83.4%
associate-/l*96.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub96.9%
remove-double-neg96.9%
distribute-frac-neg296.9%
*-inverses96.9%
metadata-eval96.9%
Simplified96.9%
(FPCore (x y z) :precision binary64 (if (<= z -4.4e+87) x (if (<= z 7.5e-67) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.4e+87) {
tmp = x;
} else if (z <= 7.5e-67) {
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 <= (-4.4d+87)) then
tmp = x
else if (z <= 7.5d-67) 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 <= -4.4e+87) {
tmp = x;
} else if (z <= 7.5e-67) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.4e+87: tmp = x elif z <= 7.5e-67: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.4e+87) tmp = x; elseif (z <= 7.5e-67) 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 <= -4.4e+87) tmp = x; elseif (z <= 7.5e-67) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.4e+87], x, If[LessEqual[z, 7.5e-67], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-67}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.4000000000000002e87 or 7.5000000000000005e-67 < z Initial program 74.2%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 79.3%
if -4.4000000000000002e87 < z < 7.5000000000000005e-67Initial program 90.7%
associate-/l*94.5%
remove-double-neg94.5%
unsub-neg94.5%
div-sub94.5%
remove-double-neg94.5%
distribute-frac-neg294.5%
*-inverses94.5%
metadata-eval94.5%
Simplified94.5%
Taylor expanded in y around inf 74.7%
associate-*l/76.2%
*-commutative76.2%
Simplified76.2%
(FPCore (x y z) :precision binary64 (if (<= z -3.55e+87) x (if (<= z 2.2e-62) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.55e+87) {
tmp = x;
} else if (z <= 2.2e-62) {
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.55d+87)) then
tmp = x
else if (z <= 2.2d-62) 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.55e+87) {
tmp = x;
} else if (z <= 2.2e-62) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.55e+87: tmp = x elif z <= 2.2e-62: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.55e+87) tmp = x; elseif (z <= 2.2e-62) 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.55e+87) tmp = x; elseif (z <= 2.2e-62) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.55e+87], x, If[LessEqual[z, 2.2e-62], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.55 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.5499999999999999e87 or 2.20000000000000017e-62 < z Initial program 74.2%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 79.3%
if -3.5499999999999999e87 < z < 2.20000000000000017e-62Initial program 90.7%
associate-/l*94.5%
remove-double-neg94.5%
unsub-neg94.5%
div-sub94.5%
remove-double-neg94.5%
distribute-frac-neg294.5%
*-inverses94.5%
metadata-eval94.5%
Simplified94.5%
Taylor expanded in y around inf 75.7%
(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 83.4%
associate-/l*96.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub96.9%
remove-double-neg96.9%
distribute-frac-neg296.9%
*-inverses96.9%
metadata-eval96.9%
Simplified96.9%
Taylor expanded in y around 0 46.3%
(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 2024185
(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))