
(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 (/ z (+ z y))))
double code(double x, double y, double z) {
return x / (z / (z + y));
}
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 / (z + y))
end function
public static double code(double x, double y, double z) {
return x / (z / (z + y));
}
def code(x, y, z): return x / (z / (z + y))
function code(x, y, z) return Float64(x / Float64(z / Float64(z + y))) end
function tmp = code(x, y, z) tmp = x / (z / (z + y)); end
code[x_, y_, z_] := N[(x / N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{z + y}}
\end{array}
Initial program 84.5%
associate-/l*96.5%
*-commutative96.5%
Applied egg-rr96.5%
clear-num96.5%
associate-*l/96.6%
*-un-lft-identity96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.6e+27) (not (<= y 3e+95))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e+27) || !(y <= 3e+95)) {
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.6d+27)) .or. (.not. (y <= 3d+95))) 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.6e+27) || !(y <= 3e+95)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e+27) or not (y <= 3e+95): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e+27) || !(y <= 3e+95)) 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.6e+27) || ~((y <= 3e+95))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e+27], N[Not[LessEqual[y, 3e+95]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+27} \lor \neg \left(y \leq 3 \cdot 10^{+95}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.60000000000000008e27 or 2.99999999999999991e95 < y Initial program 90.1%
associate-/l*90.9%
remove-double-neg90.9%
distribute-frac-neg290.9%
neg-sub090.9%
remove-double-neg90.9%
unsub-neg90.9%
div-sub90.9%
*-inverses90.9%
metadata-eval90.9%
associate--r-90.9%
neg-sub090.9%
distribute-frac-neg290.9%
remove-double-neg90.9%
sub-neg90.9%
Simplified90.9%
Taylor expanded in y around inf 75.8%
associate-*l/72.0%
*-commutative72.0%
Simplified72.0%
if -1.60000000000000008e27 < y < 2.99999999999999991e95Initial program 81.2%
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 77.2%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e+27) (not (<= y 2.8e+95))) (/ (* x y) z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e+27) || !(y <= 2.8e+95)) {
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.5d+27)) .or. (.not. (y <= 2.8d+95))) 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.5e+27) || !(y <= 2.8e+95)) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e+27) or not (y <= 2.8e+95): tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e+27) || !(y <= 2.8e+95)) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.5e+27) || ~((y <= 2.8e+95))) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e+27], N[Not[LessEqual[y, 2.8e+95]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+27} \lor \neg \left(y \leq 2.8 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.49999999999999988e27 or 2.7999999999999998e95 < y Initial program 90.1%
associate-/l*90.9%
remove-double-neg90.9%
distribute-frac-neg290.9%
neg-sub090.9%
remove-double-neg90.9%
unsub-neg90.9%
div-sub90.9%
*-inverses90.9%
metadata-eval90.9%
associate--r-90.9%
neg-sub090.9%
distribute-frac-neg290.9%
remove-double-neg90.9%
sub-neg90.9%
Simplified90.9%
Taylor expanded in y around inf 75.8%
if -1.49999999999999988e27 < y < 2.7999999999999998e95Initial program 81.2%
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 77.2%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.55e+27) (* y (/ x z)) (if (<= y 1.35e+95) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+27) {
tmp = y * (x / z);
} else if (y <= 1.35e+95) {
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 <= (-1.55d+27)) then
tmp = y * (x / z)
else if (y <= 1.35d+95) 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 <= -1.55e+27) {
tmp = y * (x / z);
} else if (y <= 1.35e+95) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e+27: tmp = y * (x / z) elif y <= 1.35e+95: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e+27) tmp = Float64(y * Float64(x / z)); elseif (y <= 1.35e+95) 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 <= -1.55e+27) tmp = y * (x / z); elseif (y <= 1.35e+95) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e+27], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.35e+95], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+27}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+95}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.54999999999999998e27Initial program 94.7%
associate-/l*91.1%
remove-double-neg91.1%
distribute-frac-neg291.1%
neg-sub091.1%
remove-double-neg91.1%
unsub-neg91.1%
div-sub91.1%
*-inverses91.1%
metadata-eval91.1%
associate--r-91.1%
neg-sub091.1%
distribute-frac-neg291.1%
remove-double-neg91.1%
sub-neg91.1%
Simplified91.1%
Taylor expanded in y around inf 74.5%
associate-*l/70.1%
*-commutative70.1%
Simplified70.1%
if -1.54999999999999998e27 < y < 1.35e95Initial program 81.2%
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 77.2%
if 1.35e95 < y Initial program 84.0%
associate-/l*90.6%
remove-double-neg90.6%
distribute-frac-neg290.6%
neg-sub090.6%
remove-double-neg90.6%
unsub-neg90.6%
div-sub90.7%
*-inverses90.7%
metadata-eval90.7%
associate--r-90.7%
neg-sub090.7%
distribute-frac-neg290.7%
remove-double-neg90.7%
sub-neg90.7%
Simplified90.7%
Taylor expanded in y around inf 77.7%
associate-*l/74.4%
*-commutative74.4%
Simplified74.4%
clear-num74.4%
un-div-inv74.4%
Applied egg-rr74.4%
Final simplification75.2%
(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 84.5%
associate-/l*96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
neg-sub096.5%
remove-double-neg96.5%
unsub-neg96.5%
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%
Final simplification96.5%
(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 84.5%
associate-/l*96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
neg-sub096.5%
remove-double-neg96.5%
unsub-neg96.5%
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 0 56.5%
Final simplification56.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 2024071
(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))