
(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 (<= z 2e-50) (- x (/ x (/ y z))) (- x (* z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2e-50) {
tmp = x - (x / (y / z));
} else {
tmp = x - (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 <= 2d-50) then
tmp = x - (x / (y / z))
else
tmp = x - (z * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2e-50) {
tmp = x - (x / (y / z));
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2e-50: tmp = x - (x / (y / z)) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2e-50) tmp = Float64(x - Float64(x / Float64(y / z))); else tmp = Float64(x - Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2e-50) tmp = x - (x / (y / z)); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2e-50], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{-50}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < 2.00000000000000002e-50Initial program 84.5%
associate-*l/79.4%
distribute-rgt-out--75.4%
associate-*r/75.4%
associate-*l/88.5%
*-inverses88.5%
*-lft-identity88.5%
Simplified88.5%
Taylor expanded in z around 0 94.3%
*-commutative94.3%
associate-/l*98.1%
Simplified98.1%
if 2.00000000000000002e-50 < z Initial program 81.3%
associate-*l/93.6%
distribute-rgt-out--90.3%
associate-*r/84.5%
associate-*l/98.4%
*-inverses98.4%
*-lft-identity98.4%
Simplified98.4%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -170000000.0) (not (<= z 8.0))) (* z (/ (- x) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -170000000.0) || !(z <= 8.0)) {
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 <= (-170000000.0d0)) .or. (.not. (z <= 8.0d0))) 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 <= -170000000.0) || !(z <= 8.0)) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -170000000.0) or not (z <= 8.0): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -170000000.0) || !(z <= 8.0)) 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 <= -170000000.0) || ~((z <= 8.0))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -170000000.0], N[Not[LessEqual[z, 8.0]], $MachinePrecision]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -170000000 \lor \neg \left(z \leq 8\right):\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7e8 or 8 < z Initial program 85.8%
associate-*l/91.2%
distribute-rgt-out--85.2%
associate-*r/85.4%
associate-*l/96.8%
*-inverses96.8%
*-lft-identity96.8%
Simplified96.8%
Taylor expanded in z around 0 89.2%
*-commutative89.2%
associate-/l*92.1%
Simplified92.1%
Taylor expanded in y around 0 73.1%
mul-1-neg73.1%
associate-*r/76.5%
distribute-rgt-neg-in76.5%
distribute-frac-neg76.5%
Simplified76.5%
if -1.7e8 < z < 8Initial program 81.4%
associate-*l/73.6%
distribute-rgt-out--72.1%
associate-*r/69.1%
associate-*l/84.4%
*-inverses84.4%
*-lft-identity84.4%
Simplified84.4%
Taylor expanded in z around 0 80.9%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (<= z 7.5e+169) (- x (* x (/ z y))) (* z (/ (- x) y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 7.5e+169) {
tmp = x - (x * (z / 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 <= 7.5d+169) then
tmp = x - (x * (z / 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 <= 7.5e+169) {
tmp = x - (x * (z / y));
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 7.5e+169: tmp = x - (x * (z / y)) else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 7.5e+169) tmp = Float64(x - Float64(x * Float64(z / y))); else tmp = Float64(z * Float64(Float64(-x) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 7.5e+169) tmp = x - (x * (z / y)); else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 7.5e+169], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.5 \cdot 10^{+169}:\\
\;\;\;\;x - x \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < 7.49999999999999992e169Initial program 83.8%
associate-*l/81.5%
distribute-rgt-out--77.3%
associate-*r/75.7%
associate-*l/90.1%
*-inverses90.1%
*-lft-identity90.1%
Simplified90.1%
Taylor expanded in z around 0 93.8%
associate-*l/97.8%
*-commutative97.8%
Simplified97.8%
if 7.49999999999999992e169 < z Initial program 82.9%
associate-*l/92.9%
distribute-rgt-out--92.9%
associate-*r/93.4%
associate-*l/96.8%
*-inverses96.8%
*-lft-identity96.8%
Simplified96.8%
Taylor expanded in z around 0 83.0%
*-commutative83.0%
associate-/l*79.0%
Simplified79.0%
Taylor expanded in y around 0 76.7%
mul-1-neg76.7%
associate-*r/91.2%
distribute-rgt-neg-in91.2%
distribute-frac-neg91.2%
Simplified91.2%
Final simplification97.1%
(FPCore (x y z) :precision binary64 (if (<= z 1e+61) (- x (* x (/ z y))) (- x (* z (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1e+61) {
tmp = x - (x * (z / y));
} else {
tmp = x - (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 <= 1d+61) then
tmp = x - (x * (z / y))
else
tmp = x - (z * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1e+61) {
tmp = x - (x * (z / y));
} else {
tmp = x - (z * (x / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1e+61: tmp = x - (x * (z / y)) else: tmp = x - (z * (x / y)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1e+61) tmp = Float64(x - Float64(x * Float64(z / y))); else tmp = Float64(x - Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1e+61) tmp = x - (x * (z / y)); else tmp = x - (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1e+61], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{+61}:\\
\;\;\;\;x - x \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < 9.99999999999999949e60Initial program 84.1%
associate-*l/80.2%
distribute-rgt-out--75.6%
associate-*r/75.6%
associate-*l/89.2%
*-inverses89.2%
*-lft-identity89.2%
Simplified89.2%
Taylor expanded in z around 0 94.6%
associate-*l/98.1%
*-commutative98.1%
Simplified98.1%
if 9.99999999999999949e60 < z Initial program 82.1%
associate-*l/93.8%
distribute-rgt-out--93.8%
associate-*r/86.2%
associate-*l/98.1%
*-inverses98.1%
*-lft-identity98.1%
Simplified98.1%
Final simplification98.1%
(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 83.7%
associate-*l/82.8%
distribute-rgt-out--79.0%
associate-*r/77.6%
associate-*l/90.9%
*-inverses90.9%
*-lft-identity90.9%
Simplified90.9%
Taylor expanded in z around 0 49.9%
Final simplification49.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 2023199
(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))