
(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 7 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) 2e+50) (+ x (* x (/ y z))) (* (+ y z) (/ x z))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y + z)) / z) <= 2e+50) {
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) <= 2d+50) 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) <= 2e+50) {
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) <= 2e+50: 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) <= 2e+50) 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) <= 2e+50) 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], 2e+50], 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 2 \cdot 10^{+50}:\\
\;\;\;\;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) < 2.0000000000000002e50Initial program 84.5%
associate-*r/98.9%
remove-double-neg98.9%
sub-neg98.9%
div-sub98.9%
distribute-frac-neg98.9%
*-inverses98.9%
metadata-eval98.9%
sub-neg98.9%
metadata-eval98.9%
*-inverses98.9%
distribute-lft-out98.9%
*-inverses98.9%
*-rgt-identity98.9%
fma-def98.9%
Simplified98.9%
fma-udef98.9%
Applied egg-rr98.9%
if 2.0000000000000002e50 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 83.1%
associate-*l/95.7%
Simplified95.7%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+112) x (if (<= z 9.6e+180) (* (+ y z) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+112) {
tmp = x;
} else if (z <= 9.6e+180) {
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 <= (-2.2d+112)) then
tmp = x
else if (z <= 9.6d+180) 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 <= -2.2e+112) {
tmp = x;
} else if (z <= 9.6e+180) {
tmp = (y + z) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+112: tmp = x elif z <= 9.6e+180: tmp = (y + z) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+112) tmp = x; elseif (z <= 9.6e+180) 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 <= -2.2e+112) tmp = x; elseif (z <= 9.6e+180) tmp = (y + z) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+112], x, If[LessEqual[z, 9.6e+180], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+112}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.6 \cdot 10^{+180}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1999999999999999e112 or 9.5999999999999994e180 < z Initial program 68.6%
associate-*l/63.3%
Simplified63.3%
Taylor expanded in z around inf 89.5%
if -2.1999999999999999e112 < z < 9.5999999999999994e180Initial program 88.9%
associate-*l/91.2%
Simplified91.2%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e-63) x (if (<= z 1.08e+46) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-63) {
tmp = x;
} else if (z <= 1.08e+46) {
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 <= (-1.2d-63)) then
tmp = x
else if (z <= 1.08d+46) 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 <= -1.2e-63) {
tmp = x;
} else if (z <= 1.08e+46) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e-63: tmp = x elif z <= 1.08e+46: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e-63) tmp = x; elseif (z <= 1.08e+46) 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 <= -1.2e-63) tmp = x; elseif (z <= 1.08e+46) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e-63], x, If[LessEqual[z, 1.08e+46], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.08 \cdot 10^{+46}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.2e-63 or 1.07999999999999994e46 < z Initial program 79.6%
associate-*l/80.6%
Simplified80.6%
Taylor expanded in z around inf 77.8%
if -1.2e-63 < z < 1.07999999999999994e46Initial program 90.4%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 75.9%
associate-*r/69.5%
Simplified69.5%
Final simplification74.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.16e-63) x (if (<= z 5.2e+45) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.16e-63) {
tmp = x;
} else if (z <= 5.2e+45) {
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.16d-63)) then
tmp = x
else if (z <= 5.2d+45) 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.16e-63) {
tmp = x;
} else if (z <= 5.2e+45) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.16e-63: tmp = x elif z <= 5.2e+45: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.16e-63) tmp = x; elseif (z <= 5.2e+45) 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.16e-63) tmp = x; elseif (z <= 5.2e+45) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.16e-63], x, If[LessEqual[z, 5.2e+45], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.16 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+45}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.16e-63 or 5.20000000000000014e45 < z Initial program 79.6%
associate-*l/80.6%
Simplified80.6%
Taylor expanded in z around inf 77.8%
if -1.16e-63 < z < 5.20000000000000014e45Initial program 90.4%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 75.9%
associate-/l*70.5%
associate-/r/72.7%
Applied egg-rr72.7%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (if (<= z -1e-63) x (if (<= z 2.1e+47) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e-63) {
tmp = x;
} else if (z <= 2.1e+47) {
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 <= (-1d-63)) then
tmp = x
else if (z <= 2.1d+47) 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 <= -1e-63) {
tmp = x;
} else if (z <= 2.1e+47) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e-63: tmp = x elif z <= 2.1e+47: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e-63) tmp = x; elseif (z <= 2.1e+47) 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 <= -1e-63) tmp = x; elseif (z <= 2.1e+47) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e-63], x, If[LessEqual[z, 2.1e+47], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+47}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.00000000000000007e-63 or 2.1e47 < z Initial program 79.6%
associate-*l/80.6%
Simplified80.6%
Taylor expanded in z around inf 77.8%
if -1.00000000000000007e-63 < z < 2.1e47Initial program 90.4%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 75.9%
associate-*r/69.5%
Simplified69.5%
associate-*r/75.9%
*-commutative75.9%
associate-/l*73.5%
Applied egg-rr73.5%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e-63) x (if (<= z 4.2e+45) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e-63) {
tmp = x;
} else if (z <= 4.2e+45) {
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 <= (-1.05d-63)) then
tmp = x
else if (z <= 4.2d+45) 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 <= -1.05e-63) {
tmp = x;
} else if (z <= 4.2e+45) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e-63: tmp = x elif z <= 4.2e+45: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e-63) tmp = x; elseif (z <= 4.2e+45) 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 <= -1.05e-63) tmp = x; elseif (z <= 4.2e+45) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e-63], x, If[LessEqual[z, 4.2e+45], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+45}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.05e-63 or 4.1999999999999999e45 < z Initial program 79.6%
associate-*l/80.6%
Simplified80.6%
Taylor expanded in z around inf 77.8%
if -1.05e-63 < z < 4.1999999999999999e45Initial program 90.4%
associate-*l/90.3%
Simplified90.3%
Taylor expanded in z around 0 75.9%
Final simplification77.0%
(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.2%
associate-*l/84.7%
Simplified84.7%
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 2023336
(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))