
(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 6 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 87.1%
associate-*l/85.5%
Simplified85.5%
associate-/r/97.4%
Applied egg-rr97.4%
Final simplification97.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.26e+225) x (if (<= y 5.4e+177) (* (- y z) (/ x y)) x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.26e+225) {
tmp = x;
} else if (y <= 5.4e+177) {
tmp = (y - 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 <= (-1.26d+225)) then
tmp = x
else if (y <= 5.4d+177) then
tmp = (y - 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 <= -1.26e+225) {
tmp = x;
} else if (y <= 5.4e+177) {
tmp = (y - z) * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.26e+225: tmp = x elif y <= 5.4e+177: tmp = (y - z) * (x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.26e+225) tmp = x; elseif (y <= 5.4e+177) tmp = Float64(Float64(y - z) * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.26e+225) tmp = x; elseif (y <= 5.4e+177) tmp = (y - z) * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.26e+225], x, If[LessEqual[y, 5.4e+177], N[(N[(y - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{+225}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+177}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.2599999999999999e225 or 5.39999999999999982e177 < y Initial program 73.9%
associate-*l/61.1%
Simplified61.1%
Taylor expanded in y around inf 85.8%
if -1.2599999999999999e225 < y < 5.39999999999999982e177Initial program 90.4%
associate-*l/91.5%
Simplified91.5%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.12e+50) (not (<= z 2.7e-41))) (* z (/ (- x) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.12e+50) || !(z <= 2.7e-41)) {
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.12d+50)) .or. (.not. (z <= 2.7d-41))) 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.12e+50) || !(z <= 2.7e-41)) {
tmp = z * (-x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.12e+50) or not (z <= 2.7e-41): tmp = z * (-x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.12e+50) || !(z <= 2.7e-41)) 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 <= -1.12e+50) || ~((z <= 2.7e-41))) tmp = z * (-x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.12e+50], N[Not[LessEqual[z, 2.7e-41]], $MachinePrecision]], N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.12 \cdot 10^{+50} \lor \neg \left(z \leq 2.7 \cdot 10^{-41}\right):\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1199999999999999e50 or 2.7e-41 < z Initial program 87.9%
associate-*l/88.7%
Simplified88.7%
Taylor expanded in y around 0 76.2%
*-commutative76.2%
associate-*r/76.2%
neg-mul-176.2%
distribute-rgt-neg-in76.2%
associate-*l/77.8%
Simplified77.8%
if -1.1199999999999999e50 < z < 2.7e-41Initial program 86.4%
associate-*l/82.7%
Simplified82.7%
Taylor expanded in y around inf 81.4%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (<= z -9.8e+49) (/ x (/ (- y) z)) (if (<= z 1.45e-41) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e+49) {
tmp = x / (-y / z);
} else if (z <= 1.45e-41) {
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 <= (-9.8d+49)) then
tmp = x / (-y / z)
else if (z <= 1.45d-41) 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 <= -9.8e+49) {
tmp = x / (-y / z);
} else if (z <= 1.45e-41) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.8e+49: tmp = x / (-y / z) elif z <= 1.45e-41: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.8e+49) tmp = Float64(x / Float64(Float64(-y) / z)); elseif (z <= 1.45e-41) 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 <= -9.8e+49) tmp = x / (-y / z); elseif (z <= 1.45e-41) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.8e+49], N[(x / N[((-y) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.45e-41], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{\frac{-y}{z}}\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-41}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -9.8000000000000003e49Initial program 91.9%
associate-*l/91.8%
Simplified91.8%
associate-/r/94.6%
Applied egg-rr94.6%
Taylor expanded in y around 0 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
if -9.8000000000000003e49 < z < 1.44999999999999989e-41Initial program 86.4%
associate-*l/82.7%
Simplified82.7%
Taylor expanded in y around inf 81.4%
if 1.44999999999999989e-41 < z Initial program 85.3%
associate-*l/86.7%
Simplified86.7%
Taylor expanded in y around 0 70.6%
*-commutative70.6%
associate-*r/70.6%
neg-mul-170.6%
distribute-rgt-neg-in70.6%
associate-*l/73.3%
Simplified73.3%
Final simplification80.2%
(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 87.1%
associate-*l/85.5%
distribute-rgt-out--83.4%
associate-*r/82.3%
associate-*l/93.3%
*-inverses93.3%
*-lft-identity93.3%
Simplified93.3%
Final simplification93.3%
(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 87.1%
associate-*l/85.5%
Simplified85.5%
Taylor expanded in y around inf 51.6%
Final simplification51.6%
(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 2023215
(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))