
(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 (if (<= y -4.1e+123) (/ (* x (+ y z)) z) (if (<= y 9.6e+87) (fma x (/ y z) x) (* (+ y z) (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.1e+123) {
tmp = (x * (y + z)) / z;
} else if (y <= 9.6e+87) {
tmp = fma(x, (y / z), x);
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -4.1e+123) tmp = Float64(Float64(x * Float64(y + z)) / z); elseif (y <= 9.6e+87) tmp = fma(x, Float64(y / z), x); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -4.1e+123], N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 9.6e+87], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+123}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{+87}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.09999999999999989e123Initial program 94.4%
if -4.09999999999999989e123 < y < 9.59999999999999926e87Initial program 83.6%
associate-*r/99.3%
remove-double-neg99.3%
sub-neg99.3%
div-sub99.3%
distribute-frac-neg99.3%
*-inverses99.3%
metadata-eval99.3%
sub-neg99.3%
metadata-eval99.3%
*-inverses99.3%
distribute-lft-out99.3%
*-inverses99.3%
*-rgt-identity99.3%
fma-def99.3%
Simplified99.3%
if 9.59999999999999926e87 < y Initial program 95.5%
associate-*l/98.3%
Simplified98.3%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.26e+123) (/ (* x (+ y z)) z) (if (<= y 4e+87) (* x (/ (+ y z) z)) (* (+ y z) (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e+123) {
tmp = (x * (y + z)) / z;
} else if (y <= 4e+87) {
tmp = x * ((y + z) / z);
} else {
tmp = (y + z) * (x / z);
}
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.26d+123)) then
tmp = (x * (y + z)) / z
else if (y <= 4d+87) then
tmp = x * ((y + z) / z)
else
tmp = (y + z) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e+123) {
tmp = (x * (y + z)) / z;
} else if (y <= 4e+87) {
tmp = x * ((y + z) / z);
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.26e+123: tmp = (x * (y + z)) / z elif y <= 4e+87: tmp = x * ((y + z) / z) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.26e+123) tmp = Float64(Float64(x * Float64(y + z)) / z); elseif (y <= 4e+87) tmp = Float64(x * Float64(Float64(y + z) / z)); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.26e+123) tmp = (x * (y + z)) / z; elseif (y <= 4e+87) tmp = x * ((y + z) / z); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.26e+123], N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 4e+87], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{+123}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+87}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.26e123Initial program 94.4%
if -1.26e123 < y < 3.9999999999999998e87Initial program 83.6%
associate-*r/99.3%
Simplified99.3%
if 3.9999999999999998e87 < y Initial program 95.5%
associate-*l/98.3%
Simplified98.3%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= z -1e-54) x (if (<= z 1.8e-35) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e-54) {
tmp = x;
} else if (z <= 1.8e-35) {
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 <= (-1d-54)) then
tmp = x
else if (z <= 1.8d-35) 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 <= -1e-54) {
tmp = x;
} else if (z <= 1.8e-35) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e-54: tmp = x elif z <= 1.8e-35: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e-54) tmp = x; elseif (z <= 1.8e-35) 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 <= -1e-54) tmp = x; elseif (z <= 1.8e-35) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e-54], x, If[LessEqual[z, 1.8e-35], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-54}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-35}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1e-54 or 1.80000000000000009e-35 < z Initial program 85.1%
associate-*r/99.1%
remove-double-neg99.1%
sub-neg99.1%
div-sub99.2%
distribute-frac-neg99.2%
*-inverses99.2%
metadata-eval99.2%
sub-neg99.2%
metadata-eval99.2%
*-inverses99.2%
distribute-lft-out99.2%
*-inverses99.2%
*-rgt-identity99.2%
fma-def99.2%
Simplified99.2%
Taylor expanded in y around 0 73.9%
if -1e-54 < z < 1.80000000000000009e-35Initial program 89.3%
associate-*r/86.6%
Simplified86.6%
Taylor expanded in y around inf 70.5%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.75e-38) x (if (<= z 3e-35) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e-38) {
tmp = x;
} else if (z <= 3e-35) {
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 (z <= (-1.75d-38)) then
tmp = x
else if (z <= 3d-35) 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 (z <= -1.75e-38) {
tmp = x;
} else if (z <= 3e-35) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.75e-38: tmp = x elif z <= 3e-35: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.75e-38) tmp = x; elseif (z <= 3e-35) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.75e-38) tmp = x; elseif (z <= 3e-35) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.75e-38], x, If[LessEqual[z, 3e-35], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-35}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7500000000000001e-38 or 2.99999999999999989e-35 < z Initial program 84.5%
associate-*r/99.9%
remove-double-neg99.9%
sub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
sub-neg99.9%
metadata-eval99.9%
*-inverses99.9%
distribute-lft-out99.9%
*-inverses99.9%
*-rgt-identity99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 75.1%
if -1.7500000000000001e-38 < z < 2.99999999999999989e-35Initial program 89.7%
associate-*r/86.4%
remove-double-neg86.4%
sub-neg86.4%
div-sub86.4%
distribute-frac-neg86.4%
*-inverses86.4%
metadata-eval86.4%
sub-neg86.4%
metadata-eval86.4%
*-inverses86.4%
distribute-lft-out86.3%
*-inverses86.3%
*-rgt-identity86.3%
fma-def86.4%
Simplified86.4%
Taylor expanded in y around inf 76.8%
associate-*r/79.6%
Simplified79.6%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= y 4.5e+124) (* x (/ (+ y z) z)) (* y (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.5e+124) {
tmp = x * ((y + z) / z);
} else {
tmp = y * (x / z);
}
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 <= 4.5d+124) then
tmp = x * ((y + z) / z)
else
tmp = y * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 4.5e+124) {
tmp = x * ((y + z) / z);
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.5e+124: tmp = x * ((y + z) / z) else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.5e+124) tmp = Float64(x * Float64(Float64(y + z) / z)); else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.5e+124) tmp = x * ((y + z) / z); else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.5e+124], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{+124}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 4.5000000000000004e124Initial program 85.7%
associate-*r/95.2%
Simplified95.2%
if 4.5000000000000004e124 < y Initial program 95.0%
associate-*r/82.5%
remove-double-neg82.5%
sub-neg82.5%
div-sub82.5%
distribute-frac-neg82.5%
*-inverses82.5%
metadata-eval82.5%
sub-neg82.5%
metadata-eval82.5%
*-inverses82.5%
distribute-lft-out82.5%
*-inverses82.5%
*-rgt-identity82.5%
fma-def82.5%
Simplified82.5%
Taylor expanded in y around inf 95.0%
associate-*r/96.3%
Simplified96.3%
Final simplification95.3%
(FPCore (x y z) :precision binary64 (if (<= y 2.1e+87) (* x (/ (+ y z) z)) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.1e+87) {
tmp = x * ((y + z) / z);
} else {
tmp = (y + z) * (x / z);
}
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.1d+87) then
tmp = x * ((y + z) / z)
else
tmp = (y + z) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.1e+87) {
tmp = x * ((y + z) / z);
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.1e+87: tmp = x * ((y + z) / z) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.1e+87) tmp = Float64(x * Float64(Float64(y + z) / z)); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.1e+87) tmp = x * ((y + z) / z); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.1e+87], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{+87}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 2.1e87Initial program 85.4%
associate-*r/95.5%
Simplified95.5%
if 2.1e87 < y Initial program 95.5%
associate-*l/98.3%
Simplified98.3%
Final simplification95.9%
(FPCore (x y z) :precision binary64 (if (<= y 3.7e+87) (/ x (/ z (+ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.7e+87) {
tmp = x / (z / (y + z));
} else {
tmp = (y + z) * (x / z);
}
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 <= 3.7d+87) then
tmp = x / (z / (y + z))
else
tmp = (y + z) * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.7e+87) {
tmp = x / (z / (y + z));
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.7e+87: tmp = x / (z / (y + z)) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.7e+87) tmp = Float64(x / Float64(z / Float64(y + z))); else tmp = Float64(Float64(y + z) * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.7e+87) tmp = x / (z / (y + z)); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.7e+87], N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.7 \cdot 10^{+87}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < 3.70000000000000003e87Initial program 85.4%
associate-/l*95.5%
Simplified95.5%
if 3.70000000000000003e87 < y Initial program 95.5%
associate-*l/98.3%
Simplified98.3%
Final simplification95.9%
(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 87.1%
associate-*r/93.3%
remove-double-neg93.3%
sub-neg93.3%
div-sub93.3%
distribute-frac-neg93.3%
*-inverses93.3%
metadata-eval93.3%
sub-neg93.3%
metadata-eval93.3%
*-inverses93.3%
distribute-lft-out93.3%
*-inverses93.3%
*-rgt-identity93.3%
fma-def93.3%
Simplified93.3%
Taylor expanded in y around 0 47.9%
Final simplification47.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 2023279
(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))