
(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) -1e+145) (* (+ y z) (/ x z)) (+ x (* x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= -1e+145) {
tmp = (y + z) * (x / z);
} else {
tmp = x + (x * (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 (((x * (y + z)) / z) <= (-1d+145)) then
tmp = (y + z) * (x / z)
else
tmp = x + (x * (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= -1e+145) {
tmp = (y + z) * (x / z);
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y + z)) / z) <= -1e+145: tmp = (y + z) * (x / z) else: tmp = x + (x * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y + z)) / z) <= -1e+145) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = Float64(x + Float64(x * Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * (y + z)) / z) <= -1e+145) tmp = (y + z) * (x / z); else tmp = x + (x * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], -1e+145], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -1 \cdot 10^{+145}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < -9.9999999999999999e144Initial program 83.2%
associate-*l/96.5%
Simplified96.5%
if -9.9999999999999999e144 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 91.7%
associate-*l/80.7%
distribute-rgt-in77.0%
*-commutative77.0%
associate-/r/94.2%
*-inverses94.2%
/-rgt-identity94.2%
associate-*r/95.9%
*-commutative95.9%
associate-*r/97.1%
fma-def97.1%
Simplified97.1%
fma-udef97.1%
Applied egg-rr97.1%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (if (<= z -3.3e+74) x (if (<= z 1.3e+135) (* (+ y z) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e+74) {
tmp = x;
} else if (z <= 1.3e+135) {
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 <= (-3.3d+74)) then
tmp = x
else if (z <= 1.3d+135) 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 <= -3.3e+74) {
tmp = x;
} else if (z <= 1.3e+135) {
tmp = (y + z) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e+74: tmp = x elif z <= 1.3e+135: tmp = (y + z) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e+74) tmp = x; elseif (z <= 1.3e+135) 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 <= -3.3e+74) tmp = x; elseif (z <= 1.3e+135) tmp = (y + z) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e+74], x, If[LessEqual[z, 1.3e+135], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+74}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+135}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.3000000000000002e74 or 1.3e135 < z Initial program 79.2%
associate-*l/65.1%
Simplified65.1%
Taylor expanded in z around inf 86.1%
if -3.3000000000000002e74 < z < 1.3e135Initial program 95.2%
associate-*l/93.8%
Simplified93.8%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e+50) x (if (<= z 1.05e+56) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+50) {
tmp = x;
} else if (z <= 1.05e+56) {
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 <= (-6.6d+50)) then
tmp = x
else if (z <= 1.05d+56) 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 <= -6.6e+50) {
tmp = x;
} else if (z <= 1.05e+56) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e+50: tmp = x elif z <= 1.05e+56: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+50) tmp = x; elseif (z <= 1.05e+56) 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 <= -6.6e+50) tmp = x; elseif (z <= 1.05e+56) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+50], x, If[LessEqual[z, 1.05e+56], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+56}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.6000000000000001e50 or 1.05000000000000009e56 < z Initial program 79.8%
associate-*l/70.5%
Simplified70.5%
Taylor expanded in z around inf 81.8%
if -6.6000000000000001e50 < z < 1.05000000000000009e56Initial program 96.4%
associate-*l/93.2%
Simplified93.2%
Taylor expanded in z around 0 74.1%
*-commutative74.1%
associate-*r/68.8%
Simplified68.8%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (if (<= z -9.2e+47) x (if (<= z 1.5e+53) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+47) {
tmp = x;
} else if (z <= 1.5e+53) {
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 <= (-9.2d+47)) then
tmp = x
else if (z <= 1.5d+53) 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 <= -9.2e+47) {
tmp = x;
} else if (z <= 1.5e+53) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e+47: tmp = x elif z <= 1.5e+53: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e+47) tmp = x; elseif (z <= 1.5e+53) 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 <= -9.2e+47) tmp = x; elseif (z <= 1.5e+53) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e+47], x, If[LessEqual[z, 1.5e+53], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+47}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+53}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.1999999999999994e47 or 1.49999999999999999e53 < z Initial program 79.8%
associate-*l/70.5%
Simplified70.5%
Taylor expanded in z around inf 81.8%
if -9.1999999999999994e47 < z < 1.49999999999999999e53Initial program 96.4%
associate-*l/93.2%
Simplified93.2%
Taylor expanded in z around 0 74.1%
associate-*r/74.5%
Simplified74.5%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= z -6.8e+47) x (if (<= z 4.3e+51) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+47) {
tmp = x;
} else if (z <= 4.3e+51) {
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 <= (-6.8d+47)) then
tmp = x
else if (z <= 4.3d+51) 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 <= -6.8e+47) {
tmp = x;
} else if (z <= 4.3e+51) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.8e+47: tmp = x elif z <= 4.3e+51: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.8e+47) tmp = x; elseif (z <= 4.3e+51) 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 <= -6.8e+47) tmp = x; elseif (z <= 4.3e+51) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.8e+47], x, If[LessEqual[z, 4.3e+51], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{+47}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{+51}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.7999999999999996e47 or 4.2999999999999997e51 < z Initial program 79.8%
associate-*l/70.5%
Simplified70.5%
Taylor expanded in z around inf 81.8%
if -6.7999999999999996e47 < z < 4.2999999999999997e51Initial program 96.4%
associate-*l/93.2%
Simplified93.2%
Taylor expanded in z around 0 74.1%
*-commutative74.1%
associate-*r/68.8%
Simplified68.8%
*-commutative68.8%
associate-/r/74.5%
Applied egg-rr74.5%
Final simplification77.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 89.8%
associate-*l/84.1%
Simplified84.1%
Taylor expanded in z around inf 47.5%
Final simplification47.5%
(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 2023195
(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))