
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
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)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
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)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (/ x (/ y (- y z))))
double code(double x, double y, double z) {
return x / (y / (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 / (y / (y - z))
end function
public static double code(double x, double y, double z) {
return x / (y / (y - z));
}
def code(x, y, z): return x / (y / (y - z))
function code(x, y, z) return Float64(x / Float64(y / Float64(y - z))) end
function tmp = code(x, y, z) tmp = x / (y / (y - z)); end
code[x_, y_, z_] := N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{y}{y - z}}
\end{array}
Initial program 85.0%
associate-/l*95.4%
Simplified95.4%
Final simplification95.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e-59) (not (<= z 3.6e-53))) (* (- x) (/ z y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-59) || !(z <= 3.6e-53)) {
tmp = -x * (z / y);
} 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.1d-59)) .or. (.not. (z <= 3.6d-53))) then
tmp = -x * (z / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e-59) || !(z <= 3.6e-53)) {
tmp = -x * (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e-59) or not (z <= 3.6e-53): tmp = -x * (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e-59) || !(z <= 3.6e-53)) tmp = Float64(Float64(-x) * Float64(z / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e-59) || ~((z <= 3.6e-53))) tmp = -x * (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e-59], N[Not[LessEqual[z, 3.6e-53]], $MachinePrecision]], N[((-x) * N[(z / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-59} \lor \neg \left(z \leq 3.6 \cdot 10^{-53}\right):\\
\;\;\;\;\left(-x\right) \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.09999999999999999e-59 or 3.5999999999999999e-53 < z Initial program 87.5%
associate-*r/90.8%
Simplified90.8%
Taylor expanded in y around 0 69.3%
neg-mul-169.3%
distribute-neg-frac69.3%
Simplified69.3%
if -3.09999999999999999e-59 < z < 3.5999999999999999e-53Initial program 81.6%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 84.4%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -7e-49) (not (<= z 3e-52))) (* z (/ (- x) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-49) || !(z <= 3e-52)) {
tmp = z * (-x / y);
} 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-49)) .or. (.not. (z <= 3d-52))) then
tmp = z * (-x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-49) || !(z <= 3e-52)) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7e-49) or not (z <= 3e-52): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7e-49) || !(z <= 3e-52)) tmp = Float64(z * Float64(Float64(-x) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7e-49) || ~((z <= 3e-52))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7e-49], N[Not[LessEqual[z, 3e-52]], $MachinePrecision]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-49} \lor \neg \left(z \leq 3 \cdot 10^{-52}\right):\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.00000000000000012e-49 or 3e-52 < z Initial program 87.3%
associate-*r/90.7%
Simplified90.7%
associate-*r/87.3%
associate-/l*91.9%
clear-num91.7%
Applied egg-rr91.7%
Taylor expanded in y around 0 75.4%
mul-1-neg75.4%
associate-*l/76.1%
*-commutative76.1%
distribute-rgt-neg-in76.1%
Simplified76.1%
if -7.00000000000000012e-49 < z < 3e-52Initial program 81.9%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 83.8%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.45e-56) (- (/ z (/ y x))) (if (<= z 2.45e-55) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e-56) {
tmp = -(z / (y / x));
} else if (z <= 2.45e-55) {
tmp = x;
} else {
tmp = z * (-x / y);
}
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.45d-56)) then
tmp = -(z / (y / x))
else if (z <= 2.45d-55) then
tmp = x
else
tmp = z * (-x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.45e-56) {
tmp = -(z / (y / x));
} else if (z <= 2.45e-55) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.45e-56: tmp = -(z / (y / x)) elif z <= 2.45e-55: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.45e-56) tmp = Float64(-Float64(z / Float64(y / x))); elseif (z <= 2.45e-55) tmp = x; else tmp = Float64(z * Float64(Float64(-x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.45e-56) tmp = -(z / (y / x)); elseif (z <= 2.45e-55) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.45e-56], (-N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), If[LessEqual[z, 2.45e-55], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-56}:\\
\;\;\;\;-\frac{z}{\frac{y}{x}}\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{-55}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -1.44999999999999996e-56Initial program 88.2%
associate-*r/90.5%
Simplified90.5%
associate-*r/88.2%
associate-/l*91.3%
clear-num91.3%
Applied egg-rr91.3%
Taylor expanded in y around 0 78.5%
mul-1-neg78.5%
associate-*l/76.3%
*-commutative76.3%
distribute-rgt-neg-in76.3%
Simplified76.3%
add-sqr-sqrt36.4%
sqrt-unprod32.0%
sqr-neg32.0%
sqrt-unprod1.1%
add-sqr-sqrt1.6%
clear-num1.6%
div-inv1.6%
frac-2neg1.6%
clear-num1.6%
distribute-neg-frac1.6%
add-sqr-sqrt1.1%
sqrt-unprod32.0%
sqr-neg32.0%
sqrt-unprod36.5%
add-sqr-sqrt76.3%
frac-2neg76.3%
clear-num76.4%
Applied egg-rr76.4%
if -1.44999999999999996e-56 < z < 2.45000000000000018e-55Initial program 81.6%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 84.4%
if 2.45000000000000018e-55 < z Initial program 86.6%
associate-*r/91.2%
Simplified91.2%
associate-*r/86.6%
associate-/l*92.8%
clear-num92.5%
Applied egg-rr92.5%
Taylor expanded in y around 0 70.8%
mul-1-neg70.8%
associate-*l/75.1%
*-commutative75.1%
distribute-rgt-neg-in75.1%
Simplified75.1%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (<= z -6e-49) (/ (* z (- x)) y) (if (<= z 5.6e-55) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e-49) {
tmp = (z * -x) / y;
} else if (z <= 5.6e-55) {
tmp = x;
} else {
tmp = z * (-x / y);
}
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 <= (-6d-49)) then
tmp = (z * -x) / y
else if (z <= 5.6d-55) then
tmp = x
else
tmp = z * (-x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6e-49) {
tmp = (z * -x) / y;
} else if (z <= 5.6e-55) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e-49: tmp = (z * -x) / y elif z <= 5.6e-55: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e-49) tmp = Float64(Float64(z * Float64(-x)) / y); elseif (z <= 5.6e-55) tmp = x; else tmp = Float64(z * Float64(Float64(-x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6e-49) tmp = (z * -x) / y; elseif (z <= 5.6e-55) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e-49], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[z, 5.6e-55], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-49}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-55}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -6e-49Initial program 87.9%
associate-*r/90.3%
Simplified90.3%
Taylor expanded in y around 0 79.2%
associate-*r/79.2%
associate-*r*79.2%
neg-mul-179.2%
Simplified79.2%
if -6e-49 < z < 5.59999999999999968e-55Initial program 81.9%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 83.8%
if 5.59999999999999968e-55 < z Initial program 86.6%
associate-*r/91.2%
Simplified91.2%
associate-*r/86.6%
associate-/l*92.8%
clear-num92.5%
Applied egg-rr92.5%
Taylor expanded in y around 0 70.8%
mul-1-neg70.8%
associate-*l/75.1%
*-commutative75.1%
distribute-rgt-neg-in75.1%
Simplified75.1%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (<= x 5.5e+110) x (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= 5.5e+110) {
tmp = x;
} else {
tmp = y * (x / y);
}
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 <= 5.5d+110) then
tmp = x
else
tmp = y * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 5.5e+110) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 5.5e+110: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 5.5e+110) tmp = x; else tmp = Float64(y * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 5.5e+110) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 5.5e+110], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{+110}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if x < 5.49999999999999996e110Initial program 88.2%
associate-*r/93.5%
Simplified93.5%
Taylor expanded in y around inf 51.6%
if 5.49999999999999996e110 < x Initial program 70.7%
Taylor expanded in y around inf 24.9%
associate-/l*44.6%
associate-/r/56.1%
Applied egg-rr56.1%
Final simplification52.4%
(FPCore (x y z) :precision binary64 (if (<= x 2.2e+109) x (/ y (/ y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2.2e+109) {
tmp = x;
} else {
tmp = y / (y / 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 <= 2.2d+109) then
tmp = x
else
tmp = y / (y / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2.2e+109) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2.2e+109: tmp = x else: tmp = y / (y / x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2.2e+109) tmp = x; else tmp = Float64(y / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2.2e+109) tmp = x; else tmp = y / (y / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2.2e+109], x, N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2 \cdot 10^{+109}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\end{array}
\end{array}
if x < 2.1999999999999999e109Initial program 88.1%
associate-*r/93.5%
Simplified93.5%
Taylor expanded in y around inf 51.1%
if 2.1999999999999999e109 < x Initial program 71.9%
Taylor expanded in y around inf 27.9%
associate-/l*46.9%
associate-/r/57.8%
Applied egg-rr57.8%
*-commutative57.8%
clear-num57.7%
div-inv59.3%
Applied egg-rr59.3%
Final simplification52.7%
(FPCore (x y z) :precision binary64 (* x (/ (- y z) y)))
double code(double x, double y, double z) {
return x * ((y - z) / y);
}
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) / y)
end function
public static double code(double x, double y, double z) {
return x * ((y - z) / y);
}
def code(x, y, z): return x * ((y - z) / y)
function code(x, y, z) return Float64(x * Float64(Float64(y - z) / y)) end
function tmp = code(x, y, z) tmp = x * ((y - z) / y); end
code[x_, y_, z_] := N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y - z}{y}
\end{array}
Initial program 85.0%
associate-*r/94.7%
Simplified94.7%
Final simplification94.7%
(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 85.0%
associate-*r/94.7%
Simplified94.7%
Taylor expanded in y around inf 50.3%
Final simplification50.3%
(FPCore (x y z) :precision binary64 (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
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.060202331921739d+104)) then
tmp = x - ((z * x) / y)
else if (z < 1.6939766013828526d+213) then
tmp = x / (y / (y - z))
else
tmp = (y - z) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z < -2.060202331921739e+104) {
tmp = x - ((z * x) / y);
} else if (z < 1.6939766013828526e+213) {
tmp = x / (y / (y - z));
} else {
tmp = (y - z) * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z < -2.060202331921739e+104: tmp = x - ((z * x) / y) elif z < 1.6939766013828526e+213: tmp = x / (y / (y - z)) else: tmp = (y - z) * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z < -2.060202331921739e+104) tmp = Float64(x - Float64(Float64(z * x) / y)); elseif (z < 1.6939766013828526e+213) tmp = Float64(x / Float64(y / Float64(y - z))); else tmp = Float64(Float64(y - z) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z < -2.060202331921739e+104) tmp = x - ((z * x) / y); elseif (z < 1.6939766013828526e+213) tmp = x / (y / (y - z)); else tmp = (y - z) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[z, -2.060202331921739e+104], N[(x - N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[Less[z, 1.6939766013828526e+213], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\
\;\;\;\;x - \frac{z \cdot x}{y}\\
\mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\
\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\end{array}
\end{array}
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))