
(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 8 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 (if (<= z -6.3e+221) (/ (* x (- y z)) y) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.3e+221) {
tmp = (x * (y - z)) / y;
} 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 (z <= (-6.3d+221)) then
tmp = (x * (y - z)) / y
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 (z <= -6.3e+221) {
tmp = (x * (y - z)) / y;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.3e+221: tmp = (x * (y - z)) / y else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.3e+221) tmp = Float64(Float64(x * Float64(y - z)) / y); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.3e+221) tmp = (x * (y - z)) / y; else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.3e+221], N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.3 \cdot 10^{+221}:\\
\;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -6.2999999999999997e221Initial program 92.1%
if -6.2999999999999997e221 < z Initial program 83.2%
*-commutative83.2%
associate-*l/97.9%
*-commutative97.9%
Simplified97.9%
*-commutative97.9%
associate-*l/83.2%
associate-/l*86.4%
Applied egg-rr86.4%
div-sub85.0%
associate-/r/95.6%
*-inverses95.6%
*-un-lft-identity95.6%
add-sqr-sqrt53.4%
sqrt-unprod66.2%
sqr-neg66.2%
sqrt-unprod24.8%
add-sqr-sqrt53.0%
associate-/l*52.8%
*-commutative52.8%
associate-/l*54.3%
add-sqr-sqrt25.8%
sqrt-unprod67.7%
sqr-neg67.7%
sqrt-unprod53.8%
add-sqr-sqrt98.1%
Applied egg-rr98.1%
Final simplification97.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e+64) (not (<= z 8.8e+80))) (* z (/ (- x) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+64) || !(z <= 8.8e+80)) {
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 <= (-3.1d+64)) .or. (.not. (z <= 8.8d+80))) 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 <= -3.1e+64) || !(z <= 8.8e+80)) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e+64) or not (z <= 8.8e+80): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e+64) || !(z <= 8.8e+80)) 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 <= -3.1e+64) || ~((z <= 8.8e+80))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e+64], N[Not[LessEqual[z, 8.8e+80]], $MachinePrecision]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+64} \lor \neg \left(z \leq 8.8 \cdot 10^{+80}\right):\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.0999999999999999e64 or 8.80000000000000011e80 < z Initial program 88.3%
*-commutative88.3%
associate-*l/87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 80.3%
mul-1-neg80.3%
associate-*l/78.2%
distribute-rgt-neg-out78.2%
Simplified78.2%
if -3.0999999999999999e64 < z < 8.80000000000000011e80Initial program 81.4%
*-commutative81.4%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 71.3%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (if (<= z -4.8e+64) (/ (* z (- x)) y) (if (<= z 8.8e+80) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+64) {
tmp = (z * -x) / y;
} else if (z <= 8.8e+80) {
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 <= (-4.8d+64)) then
tmp = (z * -x) / y
else if (z <= 8.8d+80) 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 <= -4.8e+64) {
tmp = (z * -x) / y;
} else if (z <= 8.8e+80) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.8e+64: tmp = (z * -x) / y elif z <= 8.8e+80: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.8e+64) tmp = Float64(Float64(z * Float64(-x)) / y); elseif (z <= 8.8e+80) 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 <= -4.8e+64) tmp = (z * -x) / y; elseif (z <= 8.8e+80) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.8e+64], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[z, 8.8e+80], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+64}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{elif}\;z \leq 8.8 \cdot 10^{+80}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -4.79999999999999999e64Initial program 89.3%
Taylor expanded in y around 0 84.9%
mul-1-neg84.9%
distribute-rgt-neg-out84.9%
Simplified84.9%
if -4.79999999999999999e64 < z < 8.80000000000000011e80Initial program 81.4%
*-commutative81.4%
associate-*l/99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 71.3%
if 8.80000000000000011e80 < z Initial program 87.3%
*-commutative87.3%
associate-*l/89.5%
*-commutative89.5%
Simplified89.5%
Taylor expanded in y around 0 74.8%
mul-1-neg74.8%
associate-*l/76.9%
distribute-rgt-neg-out76.9%
Simplified76.9%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= z -1e+269) (/ (* z (- x)) y) (* x (/ (- y z) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+269) {
tmp = (z * -x) / y;
} else {
tmp = x * ((y - z) / 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 <= (-1d+269)) then
tmp = (z * -x) / y
else
tmp = x * ((y - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1e+269) {
tmp = (z * -x) / y;
} else {
tmp = x * ((y - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+269: tmp = (z * -x) / y else: tmp = x * ((y - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+269) tmp = Float64(Float64(z * Float64(-x)) / y); else tmp = Float64(x * Float64(Float64(y - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e+269) tmp = (z * -x) / y; else tmp = x * ((y - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+269], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+269}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y - z}{y}\\
\end{array}
\end{array}
if z < -1e269Initial program 92.7%
Taylor expanded in y around 0 92.5%
mul-1-neg92.5%
distribute-rgt-neg-out92.5%
Simplified92.5%
if -1e269 < z Initial program 83.6%
*-commutative83.6%
associate-*l/97.2%
*-commutative97.2%
Simplified97.2%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (<= z -4.2e+265) (/ (* z (- x)) y) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+265) {
tmp = (z * -x) / y;
} 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 (z <= (-4.2d+265)) then
tmp = (z * -x) / y
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 (z <= -4.2e+265) {
tmp = (z * -x) / y;
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e+265: tmp = (z * -x) / y else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e+265) tmp = Float64(Float64(z * Float64(-x)) / y); else tmp = Float64(x - Float64(x / Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e+265) tmp = (z * -x) / y; else tmp = x - (x / (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e+265], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+265}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if z < -4.1999999999999997e265Initial program 92.7%
Taylor expanded in y around 0 92.5%
mul-1-neg92.5%
distribute-rgt-neg-out92.5%
Simplified92.5%
if -4.1999999999999997e265 < z Initial program 83.6%
*-commutative83.6%
associate-*l/97.2%
*-commutative97.2%
Simplified97.2%
*-commutative97.2%
associate-*l/83.6%
associate-/l*86.3%
Applied egg-rr86.3%
div-sub84.5%
associate-/r/95.4%
*-inverses95.4%
*-un-lft-identity95.4%
add-sqr-sqrt51.0%
sqrt-unprod63.2%
sqr-neg63.2%
sqrt-unprod24.1%
add-sqr-sqrt51.0%
associate-/l*50.8%
*-commutative50.8%
associate-/l*52.3%
add-sqr-sqrt25.0%
sqrt-unprod64.6%
sqr-neg64.6%
sqrt-unprod51.4%
add-sqr-sqrt97.4%
Applied egg-rr97.4%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (<= x 1.12e+18) x (* y (/ x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.12e+18) {
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 <= 1.12d+18) 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 <= 1.12e+18) {
tmp = x;
} else {
tmp = y * (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.12e+18: tmp = x else: tmp = y * (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.12e+18) 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 <= 1.12e+18) tmp = x; else tmp = y * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.12e+18], x, N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.12 \cdot 10^{+18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\end{array}
\end{array}
if x < 1.12e18Initial program 86.1%
*-commutative86.1%
associate-*l/93.6%
*-commutative93.6%
Simplified93.6%
Taylor expanded in y around inf 50.3%
if 1.12e18 < x Initial program 77.9%
Taylor expanded in y around inf 34.8%
associate-/l*52.5%
associate-/r/56.5%
Applied egg-rr56.5%
Final simplification51.9%
(FPCore (x y z) :precision binary64 (if (<= x 3.85e+65) x (/ y (/ y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= 3.85e+65) {
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 <= 3.85d+65) 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 <= 3.85e+65) {
tmp = x;
} else {
tmp = y / (y / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3.85e+65: tmp = x else: tmp = y / (y / x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3.85e+65) 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 <= 3.85e+65) tmp = x; else tmp = y / (y / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3.85e+65], x, N[(y / N[(y / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.85 \cdot 10^{+65}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{y}{x}}\\
\end{array}
\end{array}
if x < 3.85000000000000019e65Initial program 86.2%
*-commutative86.2%
associate-*l/93.8%
*-commutative93.8%
Simplified93.8%
Taylor expanded in y around inf 50.9%
if 3.85000000000000019e65 < x Initial program 76.1%
Taylor expanded in y around inf 30.6%
associate-/l*50.8%
associate-/r/55.4%
Applied egg-rr55.4%
*-commutative55.4%
clear-num55.3%
un-div-inv55.4%
Applied egg-rr55.4%
Final simplification51.9%
(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.1%
*-commutative84.1%
associate-*l/95.1%
*-commutative95.1%
Simplified95.1%
Taylor expanded in y around inf 50.9%
Final simplification50.9%
(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 2023322
(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))