
(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 5 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) -2e-116) (- x (* z (/ x y))) (- x (/ x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * (y - z)) / y) <= -2e-116) {
tmp = x - (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 (((x * (y - z)) / y) <= (-2d-116)) then
tmp = x - (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 (((x * (y - z)) / y) <= -2e-116) {
tmp = x - (z * (x / y));
} else {
tmp = x - (x / (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * (y - z)) / y) <= -2e-116: tmp = x - (z * (x / y)) else: tmp = x - (x / (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x * Float64(y - z)) / y) <= -2e-116) tmp = Float64(x - 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 (((x * (y - z)) / y) <= -2e-116) tmp = x - (z * (x / y)); 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] / y), $MachinePrecision], -2e-116], N[(x - N[(z * N[(x / y), $MachinePrecision]), $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)}{y} \leq -2 \cdot 10^{-116}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (-.f64 y z)) y) < -2e-116Initial program 87.1%
associate-*l/96.9%
distribute-rgt-out--89.8%
associate-*r/84.2%
associate-*l/97.1%
*-inverses97.1%
*-lft-identity97.1%
Simplified97.1%
if -2e-116 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 84.7%
associate-*l/78.9%
distribute-rgt-out--75.3%
associate-*r/80.7%
associate-*l/92.8%
*-inverses92.8%
*-lft-identity92.8%
Simplified92.8%
Taylor expanded in z around 0 95.8%
*-commutative95.8%
associate-/l*99.3%
Simplified99.3%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e+84) (not (<= z 1.05e+93))) (* z (- (/ x y))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e+84) || !(z <= 1.05e+93)) {
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 <= (-2d+84)) .or. (.not. (z <= 1.05d+93))) 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 <= -2e+84) || !(z <= 1.05e+93)) {
tmp = z * -(x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e+84) or not (z <= 1.05e+93): tmp = z * -(x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e+84) || !(z <= 1.05e+93)) 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 <= -2e+84) || ~((z <= 1.05e+93))) tmp = z * -(x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e+84], N[Not[LessEqual[z, 1.05e+93]], $MachinePrecision]], N[(z * (-N[(x / y), $MachinePrecision])), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+84} \lor \neg \left(z \leq 1.05 \cdot 10^{+93}\right):\\
\;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.00000000000000012e84 or 1.0499999999999999e93 < z Initial program 92.1%
associate-*l/92.7%
distribute-rgt-out--84.6%
associate-*r/88.4%
associate-*l/96.1%
*-inverses96.1%
*-lft-identity96.1%
Simplified96.1%
Taylor expanded in z around 0 94.2%
*-commutative94.2%
associate-/l*89.9%
Simplified89.9%
Taylor expanded in y around 0 84.4%
associate-*r/84.4%
mul-1-neg84.4%
distribute-rgt-neg-in84.4%
associate-*r/82.6%
Simplified82.6%
if -2.00000000000000012e84 < z < 1.0499999999999999e93Initial program 82.4%
associate-*l/82.6%
distribute-rgt-out--79.2%
associate-*r/78.9%
associate-*l/93.7%
*-inverses93.7%
*-lft-identity93.7%
Simplified93.7%
Taylor expanded in z around 0 77.6%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.2e+77) (not (<= z 9e+92))) (/ (* x (- z)) y) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.2e+77) || !(z <= 9e+92)) {
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 <= (-6.2d+77)) .or. (.not. (z <= 9d+92))) 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 <= -6.2e+77) || !(z <= 9e+92)) {
tmp = (x * -z) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.2e+77) or not (z <= 9e+92): tmp = (x * -z) / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.2e+77) || !(z <= 9e+92)) 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 <= -6.2e+77) || ~((z <= 9e+92))) tmp = (x * -z) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.2e+77], N[Not[LessEqual[z, 9e+92]], $MachinePrecision]], N[(N[(x * (-z)), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+77} \lor \neg \left(z \leq 9 \cdot 10^{+92}\right):\\
\;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.19999999999999997e77 or 8.9999999999999998e92 < z Initial program 92.1%
associate-*l/92.7%
distribute-rgt-out--84.6%
associate-*r/88.4%
associate-*l/96.1%
*-inverses96.1%
*-lft-identity96.1%
Simplified96.1%
Taylor expanded in z around inf 84.4%
associate-*r/84.4%
neg-mul-184.4%
distribute-rgt-neg-in84.4%
Simplified84.4%
if -6.19999999999999997e77 < z < 8.9999999999999998e92Initial program 82.4%
associate-*l/82.6%
distribute-rgt-out--79.2%
associate-*r/78.9%
associate-*l/93.7%
*-inverses93.7%
*-lft-identity93.7%
Simplified93.7%
Taylor expanded in z around 0 77.6%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (- x (* z (/ x y))))
double code(double x, double y, double z) {
return x - (z * (x / 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 - (z * (x / y))
end function
public static double code(double x, double y, double z) {
return x - (z * (x / y));
}
def code(x, y, z): return x - (z * (x / y))
function code(x, y, z) return Float64(x - Float64(z * Float64(x / y))) end
function tmp = code(x, y, z) tmp = x - (z * (x / y)); end
code[x_, y_, z_] := N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot \frac{x}{y}
\end{array}
Initial program 85.6%
associate-*l/86.0%
distribute-rgt-out--81.0%
associate-*r/82.1%
associate-*l/94.5%
*-inverses94.5%
*-lft-identity94.5%
Simplified94.5%
Final simplification94.5%
(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.6%
associate-*l/86.0%
distribute-rgt-out--81.0%
associate-*r/82.1%
associate-*l/94.5%
*-inverses94.5%
*-lft-identity94.5%
Simplified94.5%
Taylor expanded in z around 0 56.9%
Final simplification56.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 2023185
(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))