
(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 (* x (/ y z))))
double code(double x, double y, double z) {
return x + (x * (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 + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 86.1%
remove-double-neg86.1%
distribute-lft-neg-out86.1%
*-commutative86.1%
distribute-lft-neg-in86.1%
associate-/l*84.7%
distribute-neg-in84.7%
unsub-neg84.7%
div-sub81.1%
distribute-frac-neg81.1%
associate-/r/80.1%
distribute-rgt-neg-out80.1%
remove-double-neg80.1%
associate-/r/96.9%
*-inverses96.9%
*-lft-identity96.9%
*-commutative96.9%
fma-neg96.9%
remove-double-neg96.9%
Simplified96.9%
fma-udef96.9%
Applied egg-rr96.9%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.9e+187) x (if (<= z 1.5e+175) (* (+ y z) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.9e+187) {
tmp = x;
} else if (z <= 1.5e+175) {
tmp = (y + z) * (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 <= (-2.9d+187)) then
tmp = x
else if (z <= 1.5d+175) then
tmp = (y + z) * (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 <= -2.9e+187) {
tmp = x;
} else if (z <= 1.5e+175) {
tmp = (y + z) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.9e+187: tmp = x elif z <= 1.5e+175: tmp = (y + z) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.9e+187) tmp = x; elseif (z <= 1.5e+175) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.9e+187) tmp = x; elseif (z <= 1.5e+175) tmp = (y + z) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.9e+187], x, If[LessEqual[z, 1.5e+175], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{+187}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+175}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.9000000000000001e187 or 1.5000000000000001e175 < z Initial program 65.7%
associate-*l/55.9%
*-commutative55.9%
Simplified55.9%
Taylor expanded in y around 0 90.4%
if -2.9000000000000001e187 < z < 1.5000000000000001e175Initial program 90.7%
associate-*l/90.4%
*-commutative90.4%
Simplified90.4%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e-99) (not (<= y 2.4e-43))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e-99) || !(y <= 2.4e-43)) {
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.9d-99)) .or. (.not. (y <= 2.4d-43))) 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.9e-99) || !(y <= 2.4e-43)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e-99) or not (y <= 2.4e-43): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e-99) || !(y <= 2.4e-43)) 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 <= -1.9e-99) || ~((y <= 2.4e-43))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e-99], N[Not[LessEqual[y, 2.4e-43]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-99} \lor \neg \left(y \leq 2.4 \cdot 10^{-43}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8999999999999998e-99 or 2.4000000000000002e-43 < y Initial program 88.1%
associate-*l/88.6%
*-commutative88.6%
Simplified88.6%
Taylor expanded in y around inf 71.6%
associate-*r/71.1%
Simplified71.1%
if -1.8999999999999998e-99 < y < 2.4000000000000002e-43Initial program 83.2%
associate-*l/77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in y around 0 82.5%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e-99) (not (<= y 2.5e-42))) (/ x (/ z y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e-99) || !(y <= 2.5e-42)) {
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 ((y <= (-1.9d-99)) .or. (.not. (y <= 2.5d-42))) 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 ((y <= -1.9e-99) || !(y <= 2.5e-42)) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e-99) or not (y <= 2.5e-42): tmp = x / (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e-99) || !(y <= 2.5e-42)) tmp = Float64(x / Float64(z / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.9e-99) || ~((y <= 2.5e-42))) tmp = x / (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e-99], N[Not[LessEqual[y, 2.5e-42]], $MachinePrecision]], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-99} \lor \neg \left(y \leq 2.5 \cdot 10^{-42}\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8999999999999998e-99 or 2.50000000000000001e-42 < y Initial program 88.1%
associate-*l/88.6%
*-commutative88.6%
Simplified88.6%
Taylor expanded in y around inf 71.6%
associate-*r/71.1%
Simplified71.1%
associate-*r/71.6%
associate-/l*71.6%
Applied egg-rr71.6%
if -1.8999999999999998e-99 < y < 2.50000000000000001e-42Initial program 83.2%
associate-*l/77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in y around 0 82.5%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-99) (/ y (/ z x)) (if (<= y 9.2e-42) x (/ x (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-99) {
tmp = y / (z / x);
} else if (y <= 9.2e-42) {
tmp = x;
} else {
tmp = x / (z / y);
}
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.9d-99)) then
tmp = y / (z / x)
else if (y <= 9.2d-42) then
tmp = x
else
tmp = x / (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-99) {
tmp = y / (z / x);
} else if (y <= 9.2e-42) {
tmp = x;
} else {
tmp = x / (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-99: tmp = y / (z / x) elif y <= 9.2e-42: tmp = x else: tmp = x / (z / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-99) tmp = Float64(y / Float64(z / x)); elseif (y <= 9.2e-42) tmp = x; else tmp = Float64(x / Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e-99) tmp = y / (z / x); elseif (y <= 9.2e-42) tmp = x; else tmp = x / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-99], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.2e-42], x, N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-99}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-42}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if y < -1.8999999999999998e-99Initial program 87.1%
associate-*l/90.9%
*-commutative90.9%
Simplified90.9%
Taylor expanded in y around inf 74.2%
associate-*r/73.3%
Simplified73.3%
associate-*r/74.2%
*-commutative74.2%
associate-/l*76.3%
Applied egg-rr76.3%
if -1.8999999999999998e-99 < y < 9.20000000000000015e-42Initial program 83.2%
associate-*l/77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in y around 0 82.5%
if 9.20000000000000015e-42 < y Initial program 89.7%
associate-*l/84.7%
*-commutative84.7%
Simplified84.7%
Taylor expanded in y around inf 67.2%
associate-*r/67.3%
Simplified67.3%
associate-*r/67.2%
associate-/l*68.4%
Applied egg-rr68.4%
Final simplification77.1%
(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.1%
associate-*l/84.1%
*-commutative84.1%
Simplified84.1%
Taylor expanded in y around 0 48.9%
Final simplification48.9%
(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 2024019
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))