
(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.2%
associate-/l*97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x y z)
:precision binary64
(if (<= z -4.4e+51)
x
(if (or (<= z 9e-54) (and (not (<= z 5.2e-17)) (<= z 1.25e+109)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.4e+51) {
tmp = x;
} else if ((z <= 9e-54) || (!(z <= 5.2e-17) && (z <= 1.25e+109))) {
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 <= (-4.4d+51)) then
tmp = x
else if ((z <= 9d-54) .or. (.not. (z <= 5.2d-17)) .and. (z <= 1.25d+109)) 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 <= -4.4e+51) {
tmp = x;
} else if ((z <= 9e-54) || (!(z <= 5.2e-17) && (z <= 1.25e+109))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.4e+51: tmp = x elif (z <= 9e-54) or (not (z <= 5.2e-17) and (z <= 1.25e+109)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.4e+51) tmp = x; elseif ((z <= 9e-54) || (!(z <= 5.2e-17) && (z <= 1.25e+109))) 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 <= -4.4e+51) tmp = x; elseif ((z <= 9e-54) || (~((z <= 5.2e-17)) && (z <= 1.25e+109))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.4e+51], x, If[Or[LessEqual[z, 9e-54], And[N[Not[LessEqual[z, 5.2e-17]], $MachinePrecision], LessEqual[z, 1.25e+109]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{+51}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-54} \lor \neg \left(z \leq 5.2 \cdot 10^{-17}\right) \land z \leq 1.25 \cdot 10^{+109}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.39999999999999984e51 or 8.9999999999999997e-54 < z < 5.20000000000000006e-17 or 1.25e109 < z Initial program 72.9%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
if -4.39999999999999984e51 < z < 8.9999999999999997e-54 or 5.20000000000000006e-17 < z < 1.25e109Initial program 91.8%
associate-*r/95.0%
Simplified95.0%
Taylor expanded in y around inf 74.0%
associate-*r/74.8%
Simplified74.8%
Final simplification79.3%
(FPCore (x y z)
:precision binary64
(if (<= z -4.2e+51)
x
(if (<= z 2.85e-52)
(/ x (/ z y))
(if (<= z 5.2e-17) x (if (<= z 9.8e+107) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+51) {
tmp = x;
} else if (z <= 2.85e-52) {
tmp = x / (z / y);
} else if (z <= 5.2e-17) {
tmp = x;
} else if (z <= 9.8e+107) {
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 <= (-4.2d+51)) then
tmp = x
else if (z <= 2.85d-52) then
tmp = x / (z / y)
else if (z <= 5.2d-17) then
tmp = x
else if (z <= 9.8d+107) 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 <= -4.2e+51) {
tmp = x;
} else if (z <= 2.85e-52) {
tmp = x / (z / y);
} else if (z <= 5.2e-17) {
tmp = x;
} else if (z <= 9.8e+107) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e+51: tmp = x elif z <= 2.85e-52: tmp = x / (z / y) elif z <= 5.2e-17: tmp = x elif z <= 9.8e+107: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e+51) tmp = x; elseif (z <= 2.85e-52) tmp = Float64(x / Float64(z / y)); elseif (z <= 5.2e-17) tmp = x; elseif (z <= 9.8e+107) 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 <= -4.2e+51) tmp = x; elseif (z <= 2.85e-52) tmp = x / (z / y); elseif (z <= 5.2e-17) tmp = x; elseif (z <= 9.8e+107) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e+51], x, If[LessEqual[z, 2.85e-52], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5.2e-17], x, If[LessEqual[z, 9.8e+107], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+51}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.85 \cdot 10^{-52}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+107}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.2000000000000002e51 or 2.8499999999999999e-52 < z < 5.20000000000000006e-17 or 9.8000000000000003e107 < z Initial program 72.9%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
if -4.2000000000000002e51 < z < 2.8499999999999999e-52Initial program 91.4%
associate-*r/94.4%
Simplified94.4%
Taylor expanded in y around inf 75.7%
associate-/l*76.4%
Simplified76.4%
if 5.20000000000000006e-17 < z < 9.8000000000000003e107Initial program 94.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in y around inf 61.3%
associate-*r/66.4%
Simplified66.4%
Final simplification79.6%
(FPCore (x y z)
:precision binary64
(if (<= z -4.4e+51)
x
(if (<= z 1.5e-52)
(/ y (/ z x))
(if (<= z 7.4e-17) x (if (<= z 1.2e+110) (* x (/ y z)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.4e+51) {
tmp = x;
} else if (z <= 1.5e-52) {
tmp = y / (z / x);
} else if (z <= 7.4e-17) {
tmp = x;
} else if (z <= 1.2e+110) {
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 <= (-4.4d+51)) then
tmp = x
else if (z <= 1.5d-52) then
tmp = y / (z / x)
else if (z <= 7.4d-17) then
tmp = x
else if (z <= 1.2d+110) 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 <= -4.4e+51) {
tmp = x;
} else if (z <= 1.5e-52) {
tmp = y / (z / x);
} else if (z <= 7.4e-17) {
tmp = x;
} else if (z <= 1.2e+110) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.4e+51: tmp = x elif z <= 1.5e-52: tmp = y / (z / x) elif z <= 7.4e-17: tmp = x elif z <= 1.2e+110: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.4e+51) tmp = x; elseif (z <= 1.5e-52) tmp = Float64(y / Float64(z / x)); elseif (z <= 7.4e-17) tmp = x; elseif (z <= 1.2e+110) 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 <= -4.4e+51) tmp = x; elseif (z <= 1.5e-52) tmp = y / (z / x); elseif (z <= 7.4e-17) tmp = x; elseif (z <= 1.2e+110) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.4e+51], x, If[LessEqual[z, 1.5e-52], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 7.4e-17], x, If[LessEqual[z, 1.2e+110], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{+51}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-52}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;z \leq 7.4 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+110}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.39999999999999984e51 or 1.5e-52 < z < 7.3999999999999995e-17 or 1.20000000000000006e110 < z Initial program 72.9%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 86.0%
if -4.39999999999999984e51 < z < 1.5e-52Initial program 91.4%
associate-*r/94.4%
Simplified94.4%
Taylor expanded in y around inf 75.7%
associate-*r/76.0%
Simplified76.0%
associate-*r/75.7%
*-commutative75.7%
associate-/l*79.8%
Applied egg-rr79.8%
if 7.3999999999999995e-17 < z < 1.20000000000000006e110Initial program 94.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in y around inf 61.3%
associate-*r/66.4%
Simplified66.4%
Final simplification81.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(Float64(z + y) / z)) end
function tmp = code(x, y, z) tmp = x * ((z + y) / z); end
code[x_, y_, z_] := N[(x * N[(N[(z + y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{z + y}{z}
\end{array}
Initial program 84.2%
associate-*r/97.0%
Simplified97.0%
Final simplification97.0%
(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.2%
associate-*r/97.0%
Simplified97.0%
Taylor expanded in y around 0 48.0%
Final simplification48.0%
(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 2023293
(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))