
(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 (/ (+ 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(x * Float64(Float64(y + z) / z)) end
function tmp = code(x, y, z) tmp = x * ((y + z) / z); end
code[x_, y_, z_] := N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y + z}{z}
\end{array}
Initial program 84.9%
associate-*r/96.2%
Simplified96.2%
Final simplification96.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.3e-49) (not (<= y 5.9e-50))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.3e-49) || !(y <= 5.9e-50)) {
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 <= (-2.3d-49)) .or. (.not. (y <= 5.9d-50))) 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 <= -2.3e-49) || !(y <= 5.9e-50)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.3e-49) or not (y <= 5.9e-50): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.3e-49) || !(y <= 5.9e-50)) 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 <= -2.3e-49) || ~((y <= 5.9e-50))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.3e-49], N[Not[LessEqual[y, 5.9e-50]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-49} \lor \neg \left(y \leq 5.9 \cdot 10^{-50}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2999999999999999e-49 or 5.9e-50 < y Initial program 89.4%
associate-*r/92.8%
Simplified92.8%
Taylor expanded in y around inf 73.9%
associate-*r/71.6%
Simplified71.6%
if -2.2999999999999999e-49 < y < 5.9e-50Initial program 79.9%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 82.9%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.85e-49) (not (<= y 1.1e-50))) (/ x (/ z y)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.85e-49) || !(y <= 1.1e-50)) {
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 <= (-2.85d-49)) .or. (.not. (y <= 1.1d-50))) 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 <= -2.85e-49) || !(y <= 1.1e-50)) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.85e-49) or not (y <= 1.1e-50): tmp = x / (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.85e-49) || !(y <= 1.1e-50)) 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 <= -2.85e-49) || ~((y <= 1.1e-50))) tmp = x / (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.85e-49], N[Not[LessEqual[y, 1.1e-50]], $MachinePrecision]], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{-49} \lor \neg \left(y \leq 1.1 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.8500000000000002e-49 or 1.0999999999999999e-50 < y Initial program 89.4%
associate-*r/92.8%
Simplified92.8%
Taylor expanded in y around inf 73.9%
associate-/l*71.7%
Simplified71.7%
if -2.8500000000000002e-49 < y < 1.0999999999999999e-50Initial program 79.9%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 82.9%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.15e-49) (not (<= y 2.95e-49))) (/ y (/ z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-49) || !(y <= 2.95e-49)) {
tmp = y / (z / x);
} 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 <= (-2.15d-49)) .or. (.not. (y <= 2.95d-49))) then
tmp = y / (z / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.15e-49) || !(y <= 2.95e-49)) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.15e-49) or not (y <= 2.95e-49): tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.15e-49) || !(y <= 2.95e-49)) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.15e-49) || ~((y <= 2.95e-49))) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.15e-49], N[Not[LessEqual[y, 2.95e-49]], $MachinePrecision]], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-49} \lor \neg \left(y \leq 2.95 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.15000000000000008e-49 or 2.95000000000000018e-49 < y Initial program 89.4%
associate-*r/92.8%
Simplified92.8%
Taylor expanded in y around inf 73.9%
associate-*r/71.6%
Simplified71.6%
associate-*r/73.9%
*-commutative73.9%
associate-/l*73.5%
Applied egg-rr73.5%
if -2.15000000000000008e-49 < y < 2.95000000000000018e-49Initial program 79.9%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 82.9%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e-50) (/ (* x y) z) (if (<= y 5e-51) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-50) {
tmp = (x * y) / z;
} else if (y <= 5e-51) {
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.65d-50)) then
tmp = (x * y) / z
else if (y <= 5d-51) 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.65e-50) {
tmp = (x * y) / z;
} else if (y <= 5e-51) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-50: tmp = (x * y) / z elif y <= 5e-51: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-50) tmp = Float64(Float64(x * y) / z); elseif (y <= 5e-51) 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.65e-50) tmp = (x * y) / z; elseif (y <= 5e-51) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-50], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 5e-51], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-50}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.6499999999999999e-50Initial program 93.7%
associate-*r/90.5%
Simplified90.5%
Taylor expanded in y around inf 74.3%
if -1.6499999999999999e-50 < y < 5.00000000000000004e-51Initial program 79.9%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 82.9%
if 5.00000000000000004e-51 < y Initial program 85.8%
associate-*r/94.7%
Simplified94.7%
Taylor expanded in y around inf 73.5%
associate-*r/73.4%
Simplified73.4%
associate-*r/73.5%
*-commutative73.5%
associate-/l*74.6%
Applied egg-rr74.6%
Final simplification78.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.9%
associate-*r/96.2%
Simplified96.2%
Taylor expanded in y around 0 51.4%
Final simplification51.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 2023275
(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))