
(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 5 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 86.0%
associate-/l*96.3%
remove-double-neg96.3%
distribute-frac-neg296.3%
neg-sub096.3%
remove-double-neg96.3%
unsub-neg96.3%
div-sub96.3%
*-inverses96.3%
metadata-eval96.3%
associate--r-96.3%
neg-sub096.3%
distribute-frac-neg296.3%
remove-double-neg96.3%
sub-neg96.3%
Simplified96.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.4e-19) (not (<= y 2.1e+71))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.4e-19) || !(y <= 2.1e+71)) {
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 <= (-7.4d-19)) .or. (.not. (y <= 2.1d+71))) 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 <= -7.4e-19) || !(y <= 2.1e+71)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.4e-19) or not (y <= 2.1e+71): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.4e-19) || !(y <= 2.1e+71)) 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 <= -7.4e-19) || ~((y <= 2.1e+71))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.4e-19], N[Not[LessEqual[y, 2.1e+71]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-19} \lor \neg \left(y \leq 2.1 \cdot 10^{+71}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.40000000000000011e-19 or 2.09999999999999989e71 < y Initial program 87.2%
associate-/l*91.8%
remove-double-neg91.8%
distribute-frac-neg291.8%
neg-sub091.8%
remove-double-neg91.8%
unsub-neg91.8%
div-sub91.8%
*-inverses91.8%
metadata-eval91.8%
associate--r-91.8%
neg-sub091.8%
distribute-frac-neg291.8%
remove-double-neg91.8%
sub-neg91.8%
Simplified91.8%
Taylor expanded in y around inf 75.8%
associate-*l/75.4%
*-commutative75.4%
Simplified75.4%
if -7.40000000000000011e-19 < y < 2.09999999999999989e71Initial program 85.2%
associate-/l*99.3%
remove-double-neg99.3%
distribute-frac-neg299.3%
neg-sub099.3%
remove-double-neg99.3%
unsub-neg99.3%
div-sub99.4%
*-inverses99.4%
metadata-eval99.4%
associate--r-99.4%
neg-sub099.4%
distribute-frac-neg299.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in y around 0 78.2%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e-22) (not (<= y 9.2e+70))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-22) || !(y <= 9.2e+70)) {
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 <= (-6.5d-22)) .or. (.not. (y <= 9.2d+70))) 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 <= -6.5e-22) || !(y <= 9.2e+70)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-22) or not (y <= 9.2e+70): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-22) || !(y <= 9.2e+70)) 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 <= -6.5e-22) || ~((y <= 9.2e+70))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-22], N[Not[LessEqual[y, 9.2e+70]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-22} \lor \neg \left(y \leq 9.2 \cdot 10^{+70}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.50000000000000043e-22 or 9.19999999999999975e70 < y Initial program 87.2%
associate-/l*91.8%
remove-double-neg91.8%
distribute-frac-neg291.8%
neg-sub091.8%
remove-double-neg91.8%
unsub-neg91.8%
div-sub91.8%
*-inverses91.8%
metadata-eval91.8%
associate--r-91.8%
neg-sub091.8%
distribute-frac-neg291.8%
remove-double-neg91.8%
sub-neg91.8%
Simplified91.8%
Taylor expanded in y around inf 73.2%
if -6.50000000000000043e-22 < y < 9.19999999999999975e70Initial program 85.2%
associate-/l*99.3%
remove-double-neg99.3%
distribute-frac-neg299.3%
neg-sub099.3%
remove-double-neg99.3%
unsub-neg99.3%
div-sub99.4%
*-inverses99.4%
metadata-eval99.4%
associate--r-99.4%
neg-sub099.4%
distribute-frac-neg299.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in y around 0 78.2%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e-19) (* y (/ x z)) (if (<= y 3.2e+70) x (/ (* x y) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-19) {
tmp = y * (x / z);
} else if (y <= 3.2e+70) {
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 <= (-7.5d-19)) then
tmp = y * (x / z)
else if (y <= 3.2d+70) 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 <= -7.5e-19) {
tmp = y * (x / z);
} else if (y <= 3.2e+70) {
tmp = x;
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e-19: tmp = y * (x / z) elif y <= 3.2e+70: tmp = x else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e-19) tmp = Float64(y * Float64(x / z)); elseif (y <= 3.2e+70) 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 <= -7.5e-19) tmp = y * (x / z); elseif (y <= 3.2e+70) tmp = x; else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e-19], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.2e+70], x, N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-19}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+70}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if y < -7.49999999999999957e-19Initial program 87.0%
associate-/l*90.2%
remove-double-neg90.2%
distribute-frac-neg290.2%
neg-sub090.2%
remove-double-neg90.2%
unsub-neg90.2%
div-sub90.3%
*-inverses90.3%
metadata-eval90.3%
associate--r-90.3%
neg-sub090.3%
distribute-frac-neg290.3%
remove-double-neg90.3%
sub-neg90.3%
Simplified90.3%
Taylor expanded in y around inf 72.2%
associate-*l/74.2%
*-commutative74.2%
Simplified74.2%
if -7.49999999999999957e-19 < y < 3.2000000000000002e70Initial program 85.2%
associate-/l*99.3%
remove-double-neg99.3%
distribute-frac-neg299.3%
neg-sub099.3%
remove-double-neg99.3%
unsub-neg99.3%
div-sub99.4%
*-inverses99.4%
metadata-eval99.4%
associate--r-99.4%
neg-sub099.4%
distribute-frac-neg299.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
Taylor expanded in y around 0 78.2%
if 3.2000000000000002e70 < y Initial program 87.5%
Taylor expanded in y around inf 80.4%
*-commutative80.4%
Simplified80.4%
Final simplification77.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 86.0%
associate-/l*96.3%
remove-double-neg96.3%
distribute-frac-neg296.3%
neg-sub096.3%
remove-double-neg96.3%
unsub-neg96.3%
div-sub96.3%
*-inverses96.3%
metadata-eval96.3%
associate--r-96.3%
neg-sub096.3%
distribute-frac-neg296.3%
remove-double-neg96.3%
sub-neg96.3%
Simplified96.3%
Taylor expanded in y around 0 55.4%
(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 2024139
(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))