
(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 (- x (* x (/ z y))))
double code(double x, double y, double z) {
return x - (x * (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 - (x * (z / y))
end function
public static double code(double x, double y, double z) {
return x - (x * (z / y));
}
def code(x, y, z): return x - (x * (z / y))
function code(x, y, z) return Float64(x - Float64(x * Float64(z / y))) end
function tmp = code(x, y, z) tmp = x - (x * (z / y)); end
code[x_, y_, z_] := N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - x \cdot \frac{z}{y}
\end{array}
Initial program 84.6%
*-commutative84.6%
associate-/l*84.0%
div-sub79.2%
associate-/r/78.1%
associate-/r/95.8%
*-inverses95.8%
*-lft-identity95.8%
*-commutative95.8%
Simplified95.8%
Final simplification95.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (/ (- z) y))))
(if (<= z -3.5e-14)
t_0
(if (<= z -7e-133)
(* y (/ x y))
(if (or (<= z -1.05e-188) (not (<= z 820000.0))) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = x * (-z / y);
double tmp;
if (z <= -3.5e-14) {
tmp = t_0;
} else if (z <= -7e-133) {
tmp = y * (x / y);
} else if ((z <= -1.05e-188) || !(z <= 820000.0)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (-z / y)
if (z <= (-3.5d-14)) then
tmp = t_0
else if (z <= (-7d-133)) then
tmp = y * (x / y)
else if ((z <= (-1.05d-188)) .or. (.not. (z <= 820000.0d0))) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (-z / y);
double tmp;
if (z <= -3.5e-14) {
tmp = t_0;
} else if (z <= -7e-133) {
tmp = y * (x / y);
} else if ((z <= -1.05e-188) || !(z <= 820000.0)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x * (-z / y) tmp = 0 if z <= -3.5e-14: tmp = t_0 elif z <= -7e-133: tmp = y * (x / y) elif (z <= -1.05e-188) or not (z <= 820000.0): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x * Float64(Float64(-z) / y)) tmp = 0.0 if (z <= -3.5e-14) tmp = t_0; elseif (z <= -7e-133) tmp = Float64(y * Float64(x / y)); elseif ((z <= -1.05e-188) || !(z <= 820000.0)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (-z / y); tmp = 0.0; if (z <= -3.5e-14) tmp = t_0; elseif (z <= -7e-133) tmp = y * (x / y); elseif ((z <= -1.05e-188) || ~((z <= 820000.0))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.5e-14], t$95$0, If[LessEqual[z, -7e-133], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -1.05e-188], N[Not[LessEqual[z, 820000.0]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{-z}{y}\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -7 \cdot 10^{-133}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-188} \lor \neg \left(z \leq 820000\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.5000000000000002e-14 or -7.00000000000000006e-133 < z < -1.05e-188 or 8.2e5 < z Initial program 88.2%
associate-*l/86.7%
Simplified86.7%
Taylor expanded in y around 0 75.8%
associate-*r/75.8%
mul-1-neg75.8%
distribute-rgt-neg-out75.8%
associate-*r/71.9%
Simplified71.9%
if -3.5000000000000002e-14 < z < -7.00000000000000006e-133Initial program 90.9%
Taylor expanded in y around inf 53.5%
associate-*l/75.8%
Applied egg-rr75.8%
if -1.05e-188 < z < 8.2e5Initial program 78.2%
associate-*l/80.9%
Simplified80.9%
Taylor expanded in y around inf 78.9%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e-14) (not (<= z 3600000.0))) (* z (/ x (- y))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e-14) || !(z <= 3600000.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 <= (-3.8d-14)) .or. (.not. (z <= 3600000.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 <= -3.8e-14) || !(z <= 3600000.0)) {
tmp = z * (x / -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e-14) or not (z <= 3600000.0): tmp = z * (x / -y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e-14) || !(z <= 3600000.0)) tmp = Float64(z * Float64(x / Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e-14) || ~((z <= 3600000.0))) tmp = z * (x / -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e-14], N[Not[LessEqual[z, 3600000.0]], $MachinePrecision]], N[(z * N[(x / (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-14} \lor \neg \left(z \leq 3600000\right):\\
\;\;\;\;z \cdot \frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.8000000000000002e-14 or 3.6e6 < z Initial program 88.2%
associate-/l*91.8%
Simplified91.8%
Taylor expanded in y around 0 72.4%
associate-*r/72.4%
neg-mul-172.4%
Simplified72.4%
associate-/r/75.9%
Applied egg-rr75.9%
if -3.8000000000000002e-14 < z < 3.6e6Initial program 80.9%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in y around inf 73.7%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-14) (not (<= z 1200000.0))) (/ (* x (- z)) y) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-14) || !(z <= 1200000.0)) {
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 <= (-4.8d-14)) .or. (.not. (z <= 1200000.0d0))) 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 <= -4.8e-14) || !(z <= 1200000.0)) {
tmp = (x * -z) / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-14) or not (z <= 1200000.0): tmp = (x * -z) / y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-14) || !(z <= 1200000.0)) 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 <= -4.8e-14) || ~((z <= 1200000.0))) tmp = (x * -z) / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-14], N[Not[LessEqual[z, 1200000.0]], $MachinePrecision]], N[(N[(x * (-z)), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-14} \lor \neg \left(z \leq 1200000\right):\\
\;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.8e-14 or 1.2e6 < z Initial program 88.2%
Taylor expanded in y around 0 77.3%
mul-1-neg77.3%
distribute-rgt-neg-out77.3%
Simplified77.3%
if -4.8e-14 < z < 1.2e6Initial program 80.9%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in y around inf 73.7%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= z -2e-14) (* z (/ x (- y))) (if (<= z 52000.0) x (/ (- z) (/ y x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e-14) {
tmp = z * (x / -y);
} else if (z <= 52000.0) {
tmp = x;
} else {
tmp = -z / (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 (z <= (-2d-14)) then
tmp = z * (x / -y)
else if (z <= 52000.0d0) then
tmp = x
else
tmp = -z / (y / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2e-14) {
tmp = z * (x / -y);
} else if (z <= 52000.0) {
tmp = x;
} else {
tmp = -z / (y / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e-14: tmp = z * (x / -y) elif z <= 52000.0: tmp = x else: tmp = -z / (y / x) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e-14) tmp = Float64(z * Float64(x / Float64(-y))); elseif (z <= 52000.0) tmp = x; else tmp = Float64(Float64(-z) / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2e-14) tmp = z * (x / -y); elseif (z <= 52000.0) tmp = x; else tmp = -z / (y / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e-14], N[(z * N[(x / (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 52000.0], x, N[((-z) / N[(y / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-14}:\\
\;\;\;\;z \cdot \frac{x}{-y}\\
\mathbf{elif}\;z \leq 52000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{-z}{\frac{y}{x}}\\
\end{array}
\end{array}
if z < -2e-14Initial program 88.4%
associate-/l*89.9%
Simplified89.9%
Taylor expanded in y around 0 71.6%
associate-*r/71.6%
neg-mul-171.6%
Simplified71.6%
associate-/r/75.8%
Applied egg-rr75.8%
if -2e-14 < z < 52000Initial program 80.9%
associate-*l/80.0%
Simplified80.0%
Taylor expanded in y around inf 73.7%
if 52000 < z Initial program 88.0%
associate-*l/90.6%
Simplified90.6%
Taylor expanded in y around 0 76.1%
associate-*r/76.1%
mul-1-neg76.1%
distribute-rgt-neg-out76.1%
associate-*r/73.3%
Simplified73.3%
*-commutative73.3%
associate-/r/76.0%
Applied egg-rr76.0%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (<= y 5.4e+166) (* (/ x y) (- y z)) x))
double code(double x, double y, double z) {
double tmp;
if (y <= 5.4e+166) {
tmp = (x / y) * (y - z);
} 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 <= 5.4d+166) then
tmp = (x / y) * (y - z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 5.4e+166) {
tmp = (x / y) * (y - z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 5.4e+166: tmp = (x / y) * (y - z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= 5.4e+166) tmp = Float64(Float64(x / y) * Float64(y - z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 5.4e+166) tmp = (x / y) * (y - z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 5.4e+166], N[(N[(x / y), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.4 \cdot 10^{+166}:\\
\;\;\;\;\frac{x}{y} \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < 5.40000000000000023e166Initial program 86.5%
associate-*l/87.0%
Simplified87.0%
if 5.40000000000000023e166 < y Initial program 69.5%
associate-*l/63.7%
Simplified63.7%
Taylor expanded in y around inf 86.0%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e+107) (* y (/ x y)) x))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+107) {
tmp = y * (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 (x <= (-1.6d+107)) then
tmp = y * (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+107) {
tmp = y * (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e+107: tmp = y * (x / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+107) tmp = Float64(y * Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e+107) tmp = y * (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+107], N[(y * N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+107}:\\
\;\;\;\;y \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.60000000000000015e107Initial program 80.6%
Taylor expanded in y around inf 23.8%
associate-*l/54.5%
Applied egg-rr54.5%
if -1.60000000000000015e107 < x Initial program 85.6%
associate-*l/83.2%
Simplified83.2%
Taylor expanded in y around inf 48.5%
Final simplification49.6%
(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.6%
associate-*l/84.5%
Simplified84.5%
Taylor expanded in y around inf 46.3%
Final simplification46.3%
(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 2023297
(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))