
(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 (<= (/ (* x (- y z)) y) (- INFINITY)) (- x (* z (/ x y))) (- x (/ (* x z) y))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y - z)) / y) <= -((double) INFINITY)) {
tmp = x - (z * (x / y));
} else {
tmp = x - ((x * z) / y);
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (((x * (y - z)) / y) <= -Double.POSITIVE_INFINITY) {
tmp = x - (z * (x / y));
} else {
tmp = x - ((x * z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y - z)) / y) <= -math.inf: tmp = x - (z * (x / y)) else: tmp = x - ((x * z) / y) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y - z)) / y) <= Float64(-Inf)) tmp = Float64(x - Float64(z * Float64(x / y))); else tmp = Float64(x - Float64(Float64(x * z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * (y - z)) / y) <= -Inf) tmp = x - (z * (x / y)); else tmp = x - ((x * z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], (-Infinity)], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0Initial program 50.5%
associate-*l/100.0%
distribute-rgt-out--86.8%
associate-*r/45.1%
associate-*l/100.0%
*-inverses100.0%
*-lft-identity100.0%
Simplified100.0%
if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 89.9%
associate-*l/77.2%
distribute-rgt-out--75.8%
associate-*r/81.1%
associate-*l/90.1%
*-inverses90.1%
*-lft-identity90.1%
Simplified90.1%
Taylor expanded in z around 0 98.1%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65e+120) (not (<= z 2.5e-95))) (* x (/ (- z) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e+120) || !(z <= 2.5e-95)) {
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 <= (-1.65d+120)) .or. (.not. (z <= 2.5d-95))) 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 <= -1.65e+120) || !(z <= 2.5e-95)) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e+120) or not (z <= 2.5e-95): tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e+120) || !(z <= 2.5e-95)) tmp = Float64(x * Float64(Float64(-z) / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.65e+120) || ~((z <= 2.5e-95))) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e+120], N[Not[LessEqual[z, 2.5e-95]], $MachinePrecision]], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+120} \lor \neg \left(z \leq 2.5 \cdot 10^{-95}\right):\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.64999999999999995e120 or 2.4999999999999999e-95 < z Initial program 89.5%
Taylor expanded in y around 0 78.0%
mul-1-neg78.0%
associate-*l/70.2%
*-commutative70.2%
distribute-rgt-neg-in70.2%
distribute-frac-neg70.2%
Simplified70.2%
if -1.64999999999999995e120 < z < 2.4999999999999999e-95Initial program 79.2%
Taylor expanded in y around inf 76.1%
Final simplification73.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65e+120) (not (<= z 2.85e-95))) (/ (* z (- x)) y) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e+120) || !(z <= 2.85e-95)) {
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 <= (-1.65d+120)) .or. (.not. (z <= 2.85d-95))) 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 <= -1.65e+120) || !(z <= 2.85e-95)) {
tmp = (z * -x) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e+120) or not (z <= 2.85e-95): tmp = (z * -x) / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e+120) || !(z <= 2.85e-95)) tmp = Float64(Float64(z * Float64(-x)) / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.65e+120) || ~((z <= 2.85e-95))) tmp = (z * -x) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e+120], N[Not[LessEqual[z, 2.85e-95]], $MachinePrecision]], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{+120} \lor \neg \left(z \leq 2.85 \cdot 10^{-95}\right):\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.64999999999999995e120 or 2.85e-95 < z Initial program 89.5%
Taylor expanded in y around 0 78.0%
associate-*r/78.0%
neg-mul-178.0%
distribute-rgt-neg-in78.0%
Simplified78.0%
if -1.64999999999999995e120 < z < 2.85e-95Initial program 79.2%
Taylor expanded in y around inf 76.1%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+39) x (if (<= y 2.25e-10) (* z (/ (- x) y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+39) {
tmp = x;
} else if (y <= 2.25e-10) {
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 (y <= (-2.5d+39)) then
tmp = x
else if (y <= 2.25d-10) 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 (y <= -2.5e+39) {
tmp = x;
} else if (y <= 2.25e-10) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e+39: tmp = x elif y <= 2.25e-10: tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+39) tmp = x; elseif (y <= 2.25e-10) 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 (y <= -2.5e+39) tmp = x; elseif (y <= 2.25e-10) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+39], x, If[LessEqual[y, 2.25e-10], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+39}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{-10}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.50000000000000008e39 or 2.25e-10 < y Initial program 75.2%
Taylor expanded in y around inf 74.0%
if -2.50000000000000008e39 < y < 2.25e-10Initial program 94.9%
Taylor expanded in y around 0 77.5%
mul-1-neg77.5%
associate-*r/76.1%
*-commutative76.1%
distribute-rgt-neg-in76.1%
Simplified76.1%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+38) x (if (<= y 7e-10) (/ z (/ (- y) x)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+38) {
tmp = x;
} else if (y <= 7e-10) {
tmp = z / (-y / 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 (y <= (-2.5d+38)) then
tmp = x
else if (y <= 7d-10) then
tmp = z / (-y / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+38) {
tmp = x;
} else if (y <= 7e-10) {
tmp = z / (-y / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e+38: tmp = x elif y <= 7e-10: tmp = z / (-y / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+38) tmp = x; elseif (y <= 7e-10) tmp = Float64(z / Float64(Float64(-y) / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.5e+38) tmp = x; elseif (y <= 7e-10) tmp = z / (-y / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+38], x, If[LessEqual[y, 7e-10], N[(z / N[((-y) / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-10}:\\
\;\;\;\;\frac{z}{\frac{-y}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.49999999999999985e38 or 6.99999999999999961e-10 < y Initial program 75.2%
Taylor expanded in y around inf 74.0%
if -2.49999999999999985e38 < y < 6.99999999999999961e-10Initial program 94.9%
Taylor expanded in y around 0 77.5%
mul-1-neg77.5%
associate-*r/76.1%
*-commutative76.1%
distribute-rgt-neg-in76.1%
Simplified76.1%
add-sqr-sqrt35.4%
sqrt-unprod28.7%
sqr-neg28.7%
sqrt-unprod0.8%
clear-num0.8%
add-sqr-sqrt1.6%
associate-/r/1.6%
frac-2neg1.6%
clear-num1.6%
add-sqr-sqrt0.8%
sqrt-unprod37.4%
sqr-neg37.4%
sqrt-unprod40.7%
add-sqr-sqrt76.4%
distribute-neg-frac76.4%
Applied egg-rr76.4%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= z 2.35e+234) (- x (* z (/ x y))) (/ (* z (- x)) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.35e+234) {
tmp = x - (z * (x / y));
} 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 <= 2.35d+234) then
tmp = x - (z * (x / y))
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 <= 2.35e+234) {
tmp = x - (z * (x / y));
} else {
tmp = (z * -x) / y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.35e+234: tmp = x - (z * (x / y)) else: tmp = (z * -x) / y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.35e+234) tmp = Float64(x - Float64(z * Float64(x / y))); else tmp = Float64(Float64(z * Float64(-x)) / y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.35e+234) tmp = x - (z * (x / y)); else tmp = (z * -x) / y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.35e+234], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.35 \cdot 10^{+234}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\end{array}
\end{array}
if z < 2.3499999999999999e234Initial program 82.7%
associate-*l/82.3%
distribute-rgt-out--78.8%
associate-*r/76.8%
associate-*l/93.6%
*-inverses93.6%
*-lft-identity93.6%
Simplified93.6%
if 2.3499999999999999e234 < z Initial program 99.8%
Taylor expanded in y around 0 90.1%
associate-*r/90.1%
neg-mul-190.1%
distribute-rgt-neg-in90.1%
Simplified90.1%
Final simplification93.3%
(FPCore (x y z) :precision binary64 (if (<= z 1.85e+234) (- x (/ z (/ y x))) (/ (* z (- x)) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.85e+234) {
tmp = x - (z / (y / 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.85d+234) then
tmp = x - (z / (y / 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.85e+234) {
tmp = x - (z / (y / x));
} else {
tmp = (z * -x) / y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.85e+234: tmp = x - (z / (y / x)) else: tmp = (z * -x) / y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.85e+234) tmp = Float64(x - Float64(z / Float64(y / x))); else tmp = Float64(Float64(z * Float64(-x)) / y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.85e+234) tmp = x - (z / (y / x)); else tmp = (z * -x) / y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.85e+234], N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * (-x)), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.85 \cdot 10^{+234}:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\
\end{array}
\end{array}
if z < 1.84999999999999983e234Initial program 82.7%
associate-*l/82.3%
distribute-rgt-out--78.8%
associate-*r/76.8%
associate-*l/93.6%
*-inverses93.6%
*-lft-identity93.6%
Simplified93.6%
clear-num93.5%
un-div-inv93.7%
Applied egg-rr93.7%
if 1.84999999999999983e234 < z Initial program 99.8%
Taylor expanded in y around 0 90.1%
associate-*r/90.1%
neg-mul-190.1%
distribute-rgt-neg-in90.1%
Simplified90.1%
Final simplification93.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 84.0%
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 2023200
(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))