
(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 8 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 (fma x (/ y z) x))
double code(double x, double y, double z) {
return fma(x, (y / z), x);
}
function code(x, y, z) return fma(x, Float64(y / z), x) end
code[x_, y_, z_] := N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
\end{array}
Initial program 85.6%
associate-*l/85.2%
distribute-rgt-in82.3%
*-commutative82.3%
associate-/r/93.5%
*-inverses93.5%
/-rgt-identity93.5%
associate-*r/93.3%
*-commutative93.3%
associate-*r/96.2%
fma-def96.2%
Simplified96.2%
Final simplification96.2%
(FPCore (x y z) :precision binary64 (if (<= z -4.8e+188) x (if (<= z 1.15e+146) (* (/ x z) (+ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+188) {
tmp = x;
} else if (z <= 1.15e+146) {
tmp = (x / z) * (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.8d+188)) then
tmp = x
else if (z <= 1.15d+146) then
tmp = (x / z) * (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.8e+188) {
tmp = x;
} else if (z <= 1.15e+146) {
tmp = (x / z) * (y + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e+188: tmp = x elif z <= 1.15e+146: tmp = (x / z) * (y + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e+188) tmp = x; elseif (z <= 1.15e+146) tmp = Float64(Float64(x / z) * Float64(y + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.8e+188) tmp = x; elseif (z <= 1.15e+146) tmp = (x / z) * (y + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e+188], x, If[LessEqual[z, 1.15e+146], N[(N[(x / z), $MachinePrecision] * N[(y + z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+188}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+146}:\\
\;\;\;\;\frac{x}{z} \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.7999999999999999e188 or 1.15e146 < z Initial program 66.4%
associate-*l/55.5%
Simplified55.5%
Taylor expanded in z around inf 86.9%
if -4.7999999999999999e188 < z < 1.15e146Initial program 90.4%
associate-*l/92.6%
Simplified92.6%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e-28) (not (<= y 3.6e+49))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-28) || !(y <= 3.6e+49)) {
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.2d-28)) .or. (.not. (y <= 3.6d+49))) 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.2e-28) || !(y <= 3.6e+49)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e-28) or not (y <= 3.6e+49): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e-28) || !(y <= 3.6e+49)) 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.2e-28) || ~((y <= 3.6e+49))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e-28], N[Not[LessEqual[y, 3.6e+49]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-28} \lor \neg \left(y \leq 3.6 \cdot 10^{+49}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.19999999999999996e-28 or 3.59999999999999996e49 < y Initial program 90.5%
associate-*l/85.8%
Simplified85.8%
Taylor expanded in z around 0 75.9%
*-commutative75.9%
associate-*r/70.5%
Simplified70.5%
if -2.19999999999999996e-28 < y < 3.59999999999999996e49Initial program 81.2%
associate-*l/84.7%
Simplified84.7%
Taylor expanded in z around inf 74.1%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-26) (not (<= y 8.8e-13))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-26) || !(y <= 8.8e-13)) {
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 <= (-5.8d-26)) .or. (.not. (y <= 8.8d-13))) 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 <= -5.8e-26) || !(y <= 8.8e-13)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-26) or not (y <= 8.8e-13): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-26) || !(y <= 8.8e-13)) 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 <= -5.8e-26) || ~((y <= 8.8e-13))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-26], N[Not[LessEqual[y, 8.8e-13]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-26} \lor \neg \left(y \leq 8.8 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.7999999999999996e-26 or 8.79999999999999986e-13 < y Initial program 89.5%
associate-*l/85.4%
Simplified85.4%
Taylor expanded in z around 0 73.2%
associate-*r/71.2%
Simplified71.2%
if -5.7999999999999996e-26 < y < 8.79999999999999986e-13Initial program 81.1%
associate-*l/85.0%
Simplified85.0%
Taylor expanded in z around inf 77.0%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.12e-29) (* y (/ x z)) (if (<= y 4.3e-13) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.12e-29) {
tmp = y * (x / z);
} else if (y <= 4.3e-13) {
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.12d-29)) then
tmp = y * (x / z)
else if (y <= 4.3d-13) 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.12e-29) {
tmp = y * (x / z);
} else if (y <= 4.3e-13) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.12e-29: tmp = y * (x / z) elif y <= 4.3e-13: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.12e-29) tmp = Float64(y * Float64(x / z)); elseif (y <= 4.3e-13) 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.12e-29) tmp = y * (x / z); elseif (y <= 4.3e-13) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.12e-29], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.3e-13], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.12 \cdot 10^{-29}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -1.11999999999999995e-29Initial program 91.3%
associate-*l/84.4%
Simplified84.4%
Taylor expanded in z around 0 73.8%
associate-*r/69.8%
Simplified69.8%
if -1.11999999999999995e-29 < y < 4.2999999999999999e-13Initial program 81.1%
associate-*l/85.0%
Simplified85.0%
Taylor expanded in z around inf 77.0%
if 4.2999999999999999e-13 < y Initial program 87.7%
associate-*l/86.4%
Simplified86.4%
Taylor expanded in z around 0 72.6%
*-commutative72.6%
associate-*r/71.2%
Simplified71.2%
*-commutative71.2%
associate-/r/72.7%
Applied egg-rr72.7%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (<= y -9.2e-27) (/ (* x y) z) (if (<= y 4.7e-12) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.2e-27) {
tmp = (x * y) / z;
} else if (y <= 4.7e-12) {
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 <= (-9.2d-27)) then
tmp = (x * y) / z
else if (y <= 4.7d-12) 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 <= -9.2e-27) {
tmp = (x * y) / z;
} else if (y <= 4.7e-12) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.2e-27: tmp = (x * y) / z elif y <= 4.7e-12: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.2e-27) tmp = Float64(Float64(x * y) / z); elseif (y <= 4.7e-12) 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 <= -9.2e-27) tmp = (x * y) / z; elseif (y <= 4.7e-12) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.2e-27], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 4.7e-12], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-27}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -9.1999999999999998e-27Initial program 91.3%
associate-*l/84.4%
Simplified84.4%
Taylor expanded in z around 0 73.8%
if -9.1999999999999998e-27 < y < 4.69999999999999976e-12Initial program 81.1%
associate-*l/85.0%
Simplified85.0%
Taylor expanded in z around inf 77.0%
if 4.69999999999999976e-12 < y Initial program 87.7%
associate-*l/86.4%
Simplified86.4%
Taylor expanded in z around 0 72.6%
*-commutative72.6%
associate-*r/71.2%
Simplified71.2%
*-commutative71.2%
associate-/r/72.7%
Applied egg-rr72.7%
Final simplification75.0%
(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 85.6%
associate-*l/85.2%
distribute-rgt-in82.3%
*-commutative82.3%
associate-/r/93.5%
*-inverses93.5%
/-rgt-identity93.5%
associate-*r/93.3%
*-commutative93.3%
associate-*r/96.2%
fma-def96.2%
Simplified96.2%
fma-udef96.2%
Applied egg-rr96.2%
Final simplification96.2%
(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 85.6%
associate-*l/85.2%
Simplified85.2%
Taylor expanded in z around inf 49.2%
Final simplification49.2%
(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 2023171
(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))