
(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 9 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 (<= z -1e-15) (fma x (/ y z) x) (if (<= z 1e-6) (/ (* x (+ z y)) z) (+ x (* x (/ y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e-15) {
tmp = fma(x, (y / z), x);
} else if (z <= 1e-6) {
tmp = (x * (z + y)) / z;
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1e-15) tmp = fma(x, Float64(y / z), x); elseif (z <= 1e-6) tmp = Float64(Float64(x * Float64(z + y)) / z); else tmp = Float64(x + Float64(x * Float64(y / z))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1e-15], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 1e-6], N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\
\mathbf{elif}\;z \leq 10^{-6}:\\
\;\;\;\;\frac{x \cdot \left(z + y\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if z < -1.0000000000000001e-15Initial program 73.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%
if -1.0000000000000001e-15 < z < 9.99999999999999955e-7Initial program 95.8%
if 9.99999999999999955e-7 < z Initial program 70.0%
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%
fma-udef99.9%
Applied egg-rr99.9%
Final simplification97.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e-16) (not (<= z 1e-6))) (+ x (* x (/ y z))) (/ (* x (+ z y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-16) || !(z <= 1e-6)) {
tmp = x + (x * (y / z));
} else {
tmp = (x * (z + y)) / 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 ((z <= (-9d-16)) .or. (.not. (z <= 1d-6))) then
tmp = x + (x * (y / z))
else
tmp = (x * (z + y)) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-16) || !(z <= 1e-6)) {
tmp = x + (x * (y / z));
} else {
tmp = (x * (z + y)) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e-16) or not (z <= 1e-6): tmp = x + (x * (y / z)) else: tmp = (x * (z + y)) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e-16) || !(z <= 1e-6)) tmp = Float64(x + Float64(x * Float64(y / z))); else tmp = Float64(Float64(x * Float64(z + y)) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e-16) || ~((z <= 1e-6))) tmp = x + (x * (y / z)); else tmp = (x * (z + y)) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e-16], N[Not[LessEqual[z, 1e-6]], $MachinePrecision]], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-16} \lor \neg \left(z \leq 10^{-6}\right):\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(z + y\right)}{z}\\
\end{array}
\end{array}
if z < -9.0000000000000003e-16 or 9.99999999999999955e-7 < z Initial program 71.7%
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%
fma-udef99.9%
Applied egg-rr99.9%
if -9.0000000000000003e-16 < z < 9.99999999999999955e-7Initial program 95.8%
Final simplification97.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.05e+180) x (if (<= z 9.8e+79) (* (+ z y) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.05e+180) {
tmp = x;
} else if (z <= 9.8e+79) {
tmp = (z + 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 <= (-2.05d+180)) then
tmp = x
else if (z <= 9.8d+79) then
tmp = (z + 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 <= -2.05e+180) {
tmp = x;
} else if (z <= 9.8e+79) {
tmp = (z + y) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.05e+180: tmp = x elif z <= 9.8e+79: tmp = (z + y) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.05e+180) tmp = x; elseif (z <= 9.8e+79) tmp = Float64(Float64(z + y) * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.05e+180) tmp = x; elseif (z <= 9.8e+79) tmp = (z + y) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.05e+180], x, If[LessEqual[z, 9.8e+79], N[(N[(z + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.05 \cdot 10^{+180}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+79}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.05e180 or 9.7999999999999997e79 < z Initial program 59.3%
associate-*l/60.3%
Simplified60.3%
Taylor expanded in z around inf 88.7%
if -2.05e180 < z < 9.7999999999999997e79Initial program 92.8%
associate-*l/91.4%
Simplified91.4%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (<= z -7e-94) x (if (<= z 1.6e-104) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e-94) {
tmp = x;
} else if (z <= 1.6e-104) {
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 <= (-7d-94)) then
tmp = x
else if (z <= 1.6d-104) 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 <= -7e-94) {
tmp = x;
} else if (z <= 1.6e-104) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e-94: tmp = x elif z <= 1.6e-104: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e-94) tmp = x; elseif (z <= 1.6e-104) 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 <= -7e-94) tmp = x; elseif (z <= 1.6e-104) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e-94], x, If[LessEqual[z, 1.6e-104], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-94}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-104}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.99999999999999996e-94 or 1.59999999999999994e-104 < z Initial program 78.2%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 72.4%
if -6.99999999999999996e-94 < z < 1.59999999999999994e-104Initial program 95.0%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 85.7%
associate-*r/75.7%
Simplified75.7%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= z -5.4e-108) x (if (<= z 6.3e-105) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.4e-108) {
tmp = x;
} else if (z <= 6.3e-105) {
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 <= (-5.4d-108)) then
tmp = x
else if (z <= 6.3d-105) 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 <= -5.4e-108) {
tmp = x;
} else if (z <= 6.3e-105) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.4e-108: tmp = x elif z <= 6.3e-105: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.4e-108) tmp = x; elseif (z <= 6.3e-105) 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 <= -5.4e-108) tmp = x; elseif (z <= 6.3e-105) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.4e-108], x, If[LessEqual[z, 6.3e-105], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{-108}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.3 \cdot 10^{-105}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4000000000000001e-108 or 6.3e-105 < z Initial program 78.2%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 72.4%
if -5.4000000000000001e-108 < z < 6.3e-105Initial program 95.0%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 85.7%
associate-/l*75.8%
associate-/r/80.7%
Applied egg-rr80.7%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= z -9e-102) x (if (<= z 4.1e-104) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e-102) {
tmp = x;
} else if (z <= 4.1e-104) {
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 (z <= (-9d-102)) then
tmp = x
else if (z <= 4.1d-104) 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 (z <= -9e-102) {
tmp = x;
} else if (z <= 4.1e-104) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e-102: tmp = x elif z <= 4.1e-104: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e-102) tmp = x; elseif (z <= 4.1e-104) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e-102) tmp = x; elseif (z <= 4.1e-104) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e-102], x, If[LessEqual[z, 4.1e-104], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-102}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-104}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.99999999999999999e-102 or 4.09999999999999984e-104 < z Initial program 78.2%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 72.4%
if -8.99999999999999999e-102 < z < 4.09999999999999984e-104Initial program 95.0%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 85.7%
associate-*r/75.7%
Simplified75.7%
associate-*r/85.7%
*-commutative85.7%
associate-/l*82.3%
Applied egg-rr82.3%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (<= z -8.8e-94) x (if (<= z 4.1e-104) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.8e-94) {
tmp = x;
} else if (z <= 4.1e-104) {
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 <= (-8.8d-94)) then
tmp = x
else if (z <= 4.1d-104) 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 <= -8.8e-94) {
tmp = x;
} else if (z <= 4.1e-104) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.8e-94: tmp = x elif z <= 4.1e-104: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.8e-94) tmp = x; elseif (z <= 4.1e-104) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.8e-94) tmp = x; elseif (z <= 4.1e-104) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.8e-94], x, If[LessEqual[z, 4.1e-104], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.8 \cdot 10^{-94}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-104}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.80000000000000004e-94 or 4.09999999999999984e-104 < z Initial program 78.2%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in z around inf 72.4%
if -8.80000000000000004e-94 < z < 4.09999999999999984e-104Initial program 95.0%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 85.7%
Final simplification77.3%
(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 84.4%
associate-*r/94.4%
remove-double-neg94.4%
sub-neg94.4%
div-sub94.4%
distribute-frac-neg94.4%
*-inverses94.4%
metadata-eval94.4%
sub-neg94.4%
metadata-eval94.4%
*-inverses94.4%
distribute-lft-out94.4%
*-inverses94.4%
*-rgt-identity94.4%
fma-def94.4%
Simplified94.4%
fma-udef94.4%
Applied egg-rr94.4%
Final simplification94.4%
(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.4%
associate-*l/83.6%
Simplified83.6%
Taylor expanded in z around inf 50.4%
Final simplification50.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 2023308
(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))