
(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 86.0%
associate-*l/80.9%
Simplified80.9%
associate-/r/97.8%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e-5) (not (<= z 1.95e+81))) (* x (/ (- z) y)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e-5) || !(z <= 1.95e+81)) {
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 <= (-4d-5)) .or. (.not. (z <= 1.95d+81))) 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 <= -4e-5) || !(z <= 1.95e+81)) {
tmp = x * (-z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e-5) or not (z <= 1.95e+81): tmp = x * (-z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e-5) || !(z <= 1.95e+81)) 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 <= -4e-5) || ~((z <= 1.95e+81))) tmp = x * (-z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e-5], N[Not[LessEqual[z, 1.95e+81]], $MachinePrecision]], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-5} \lor \neg \left(z \leq 1.95 \cdot 10^{+81}\right):\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.00000000000000033e-5 or 1.95e81 < z Initial program 91.8%
associate-*r/94.5%
div-sub94.5%
*-inverses94.5%
Simplified94.5%
Taylor expanded in z around inf 79.8%
associate-*r/79.8%
mul-1-neg79.8%
distribute-rgt-neg-out79.8%
associate-*r/78.2%
Simplified78.2%
if -4.00000000000000033e-5 < z < 1.95e81Initial program 82.1%
associate-*r/100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 80.4%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (<= z -3.6e-11) (* x (/ (- z) y)) (if (<= z 4.2e+81) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.6e-11) {
tmp = x * (-z / y);
} else if (z <= 4.2e+81) {
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 <= (-3.6d-11)) then
tmp = x * (-z / y)
else if (z <= 4.2d+81) 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 <= -3.6e-11) {
tmp = x * (-z / y);
} else if (z <= 4.2e+81) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.6e-11: tmp = x * (-z / y) elif z <= 4.2e+81: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.6e-11) tmp = Float64(x * Float64(Float64(-z) / y)); elseif (z <= 4.2e+81) 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 <= -3.6e-11) tmp = x * (-z / y); elseif (z <= 4.2e+81) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.6e-11], N[(x * N[((-z) / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.2e+81], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{-11}:\\
\;\;\;\;x \cdot \frac{-z}{y}\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+81}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -3.59999999999999985e-11Initial program 95.0%
associate-*r/96.5%
div-sub96.5%
*-inverses96.5%
Simplified96.5%
Taylor expanded in z around inf 79.6%
associate-*r/79.6%
mul-1-neg79.6%
distribute-rgt-neg-out79.6%
associate-*r/79.4%
Simplified79.4%
if -3.59999999999999985e-11 < z < 4.1999999999999997e81Initial program 82.1%
associate-*r/100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 80.4%
if 4.1999999999999997e81 < z Initial program 87.9%
associate-*r/92.0%
div-sub92.0%
*-inverses92.0%
Simplified92.0%
Taylor expanded in z around inf 80.1%
mul-1-neg80.1%
*-commutative80.1%
associate-*r/81.8%
distribute-lft-neg-out81.8%
Simplified81.8%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e-5) (/ x (/ (- y) z)) (if (<= z 9.2e+80) x (* z (/ (- x) y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e-5) {
tmp = x / (-y / z);
} else if (z <= 9.2e+80) {
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 <= (-1.4d-5)) then
tmp = x / (-y / z)
else if (z <= 9.2d+80) 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 <= -1.4e-5) {
tmp = x / (-y / z);
} else if (z <= 9.2e+80) {
tmp = x;
} else {
tmp = z * (-x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e-5: tmp = x / (-y / z) elif z <= 9.2e+80: tmp = x else: tmp = z * (-x / y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e-5) tmp = Float64(x / Float64(Float64(-y) / z)); elseif (z <= 9.2e+80) 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 <= -1.4e-5) tmp = x / (-y / z); elseif (z <= 9.2e+80) tmp = x; else tmp = z * (-x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e-5], N[(x / N[((-y) / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.2e+80], x, N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{\frac{-y}{z}}\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+80}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y}\\
\end{array}
\end{array}
if z < -1.39999999999999998e-5Initial program 95.0%
associate-*l/83.6%
Simplified83.6%
associate-/r/97.0%
Applied egg-rr97.0%
Taylor expanded in y around 0 79.9%
neg-mul-179.9%
distribute-neg-frac79.9%
Simplified79.9%
if -1.39999999999999998e-5 < z < 9.20000000000000016e80Initial program 82.1%
associate-*r/100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in z around 0 80.4%
if 9.20000000000000016e80 < z Initial program 87.9%
associate-*r/92.0%
div-sub92.0%
*-inverses92.0%
Simplified92.0%
Taylor expanded in z around inf 80.1%
mul-1-neg80.1%
*-commutative80.1%
associate-*r/81.8%
distribute-lft-neg-out81.8%
Simplified81.8%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (* x (- 1.0 (/ z y))))
double code(double x, double y, double z) {
return x * (1.0 - (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 * (1.0d0 - (z / y))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (z / y));
}
def code(x, y, z): return x * (1.0 - (z / y))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(z / y))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (z / y)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{z}{y}\right)
\end{array}
Initial program 86.0%
associate-*r/97.7%
div-sub97.8%
*-inverses97.8%
Simplified97.8%
Final simplification97.8%
(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 86.0%
associate-*r/97.7%
div-sub97.8%
*-inverses97.8%
Simplified97.8%
Taylor expanded in z around 0 54.9%
Final simplification54.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 2023302
(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))