
(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 (if (<= (/ (* x (+ y z)) z) 4e-37) (+ x (* x (/ y z))) (/ (+ y z) (/ z x))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 4e-37) {
tmp = x + (x * (y / z));
} else {
tmp = (y + z) / (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 (((x * (y + z)) / z) <= 4d-37) then
tmp = x + (x * (y / z))
else
tmp = (y + z) / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 4e-37) {
tmp = x + (x * (y / z));
} else {
tmp = (y + z) / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y + z)) / z) <= 4e-37: tmp = x + (x * (y / z)) else: tmp = (y + z) / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y + z)) / z) <= 4e-37) tmp = Float64(x + Float64(x * Float64(y / z))); else tmp = Float64(Float64(y + z) / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * (y + z)) / z) <= 4e-37) tmp = x + (x * (y / z)); else tmp = (y + z) / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 4e-37], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] / N[(z / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 4 \cdot 10^{-37}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y + z}{\frac{z}{x}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 4.00000000000000027e-37Initial program 87.4%
associate-*l/75.2%
distribute-rgt-in70.4%
*-commutative70.4%
associate-/r/95.4%
*-inverses95.4%
/-rgt-identity95.4%
associate-*r/95.2%
*-commutative95.2%
associate-*r/99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
if 4.00000000000000027e-37 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 85.3%
associate-*l/96.7%
Simplified96.7%
*-commutative96.7%
clear-num96.5%
un-div-inv96.8%
+-commutative96.8%
Applied egg-rr96.8%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= (/ (* x (+ y z)) z) 500000000000.0) (+ x (* x (/ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 500000000000.0) {
tmp = x + (x * (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 (((x * (y + z)) / z) <= 500000000000.0d0) then
tmp = x + (x * (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 (((x * (y + z)) / z) <= 500000000000.0) {
tmp = x + (x * (y / z));
} else {
tmp = (y + z) * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y + z)) / z) <= 500000000000.0: tmp = x + (x * (y / z)) else: tmp = (y + z) * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y + z)) / z) <= 500000000000.0) tmp = Float64(x + Float64(x * 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 (((x * (y + z)) / z) <= 500000000000.0) tmp = x + (x * (y / z)); else tmp = (y + z) * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 500000000000.0], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 500000000000:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 5e11Initial program 88.1%
associate-*l/76.4%
distribute-rgt-in71.9%
*-commutative71.9%
associate-/r/95.7%
*-inverses95.7%
/-rgt-identity95.7%
associate-*r/95.5%
*-commutative95.5%
associate-*r/99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
if 5e11 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 83.7%
associate-*l/96.4%
Simplified96.4%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.4e+208) x (if (<= z 1.15e+132) (* (+ y z) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.4e+208) {
tmp = x;
} else if (z <= 1.15e+132) {
tmp = (y + z) * (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 <= (-6.4d+208)) then
tmp = x
else if (z <= 1.15d+132) then
tmp = (y + z) * (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 <= -6.4e+208) {
tmp = x;
} else if (z <= 1.15e+132) {
tmp = (y + z) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.4e+208: tmp = x elif z <= 1.15e+132: tmp = (y + z) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.4e+208) tmp = x; elseif (z <= 1.15e+132) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.4e+208) tmp = x; elseif (z <= 1.15e+132) tmp = (y + z) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.4e+208], x, If[LessEqual[z, 1.15e+132], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.4 \cdot 10^{+208}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+132}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.4000000000000002e208 or 1.1500000000000001e132 < z Initial program 71.1%
associate-*l/55.0%
Simplified55.0%
Taylor expanded in z around inf 89.3%
if -6.4000000000000002e208 < z < 1.1500000000000001e132Initial program 91.6%
associate-*l/91.7%
Simplified91.7%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e-39) (not (<= y 3.8e-20))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-39) || !(y <= 3.8e-20)) {
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 <= (-1.25d-39)) .or. (.not. (y <= 3.8d-20))) 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 <= -1.25e-39) || !(y <= 3.8e-20)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e-39) or not (y <= 3.8e-20): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e-39) || !(y <= 3.8e-20)) 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 <= -1.25e-39) || ~((y <= 3.8e-20))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e-39], N[Not[LessEqual[y, 3.8e-20]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-39} \lor \neg \left(y \leq 3.8 \cdot 10^{-20}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.25e-39 or 3.7999999999999998e-20 < y Initial program 88.8%
associate-*l/88.0%
Simplified88.0%
Taylor expanded in z around 0 72.8%
*-commutative72.8%
associate-*r/71.4%
Simplified71.4%
if -1.25e-39 < y < 3.7999999999999998e-20Initial program 84.5%
associate-*l/77.6%
Simplified77.6%
Taylor expanded in z around inf 81.6%
Final simplification76.5%
(FPCore (x y z) :precision binary64 (if (<= y -3e-41) (* x (/ y z)) (if (<= y 6.2e-18) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e-41) {
tmp = x * (y / z);
} else if (y <= 6.2e-18) {
tmp = x;
} 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 <= (-3d-41)) then
tmp = x * (y / z)
else if (y <= 6.2d-18) then
tmp = x
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 <= -3e-41) {
tmp = x * (y / z);
} else if (y <= 6.2e-18) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e-41: tmp = x * (y / z) elif y <= 6.2e-18: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e-41) tmp = Float64(x * Float64(y / z)); elseif (y <= 6.2e-18) tmp = x; else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e-41) tmp = x * (y / z); elseif (y <= 6.2e-18) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e-41], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.2e-18], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-41}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.99999999999999989e-41Initial program 85.7%
associate-*l/86.3%
Simplified86.3%
Taylor expanded in z around 0 69.4%
*-commutative69.4%
associate-*r/72.3%
Simplified72.3%
if -2.99999999999999989e-41 < y < 6.20000000000000014e-18Initial program 84.5%
associate-*l/77.6%
Simplified77.6%
Taylor expanded in z around inf 81.6%
if 6.20000000000000014e-18 < y Initial program 92.2%
associate-*l/89.9%
Simplified89.9%
Taylor expanded in z around 0 76.4%
associate-*r/77.8%
Simplified77.8%
Final simplification78.3%
(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 86.7%
associate-*l/82.8%
Simplified82.8%
Taylor expanded in z around inf 53.2%
Final simplification53.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 2023242
(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))