
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + 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 + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + 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 + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
(FPCore (x y z) :precision binary64 (fma 3.0 x (fma 2.0 y z)))
double code(double x, double y, double z) {
return fma(3.0, x, fma(2.0, y, z));
}
function code(x, y, z) return fma(3.0, x, fma(2.0, y, z)) end
code[x_, y_, z_] := N[(3.0 * x + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x, \mathsf{fma}\left(2, y, z\right)\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.08e+74) (not (<= z 1.2e+53))) (fma 3.0 x z) (fma 3.0 x (+ y y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.08e+74) || !(z <= 1.2e+53)) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(3.0, x, (y + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.08e+74) || !(z <= 1.2e+53)) tmp = fma(3.0, x, z); else tmp = fma(3.0, x, Float64(y + y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.08e+74], N[Not[LessEqual[z, 1.2e+53]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.08 \cdot 10^{+74} \lor \neg \left(z \leq 1.2 \cdot 10^{+53}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\end{array}
\end{array}
if z < -1.08e74 or 1.2e53 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6495.7
Applied rewrites95.7%
if -1.08e74 < z < 1.2e53Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6492.4
Applied rewrites92.4%
Taylor expanded in x around 0
Applied rewrites92.5%
Applied rewrites92.5%
Final simplification93.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e+67) (not (<= x 9.8e+73))) (fma 3.0 x z) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+67) || !(x <= 9.8e+73)) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -8e+67) || !(x <= 9.8e+73)) tmp = fma(3.0, x, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e+67], N[Not[LessEqual[x, 9.8e+73]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+67} \lor \neg \left(x \leq 9.8 \cdot 10^{+73}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -7.99999999999999986e67 or 9.7999999999999998e73 < x Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6486.8
Applied rewrites86.8%
if -7.99999999999999986e67 < x < 9.7999999999999998e73Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6491.9
Applied rewrites91.9%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e+129) (not (<= x 7.5e+80))) (* 3.0 x) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e+129) || !(x <= 7.5e+80)) {
tmp = 3.0 * x;
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e+129) || !(x <= 7.5e+80)) tmp = Float64(3.0 * x); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e+129], N[Not[LessEqual[x, 7.5e+80]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+129} \lor \neg \left(x \leq 7.5 \cdot 10^{+80}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -6.4999999999999995e129 or 7.49999999999999994e80 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6473.6
Applied rewrites73.6%
if -6.4999999999999995e129 < x < 7.49999999999999994e80Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.6
Applied rewrites89.6%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e+64) (not (<= x 9.8e+73))) (* 3.0 x) (+ y y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+64) || !(x <= 9.8e+73)) {
tmp = 3.0 * x;
} else {
tmp = y + 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 ((x <= (-9d+64)) .or. (.not. (x <= 9.8d+73))) then
tmp = 3.0d0 * x
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+64) || !(x <= 9.8e+73)) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e+64) or not (x <= 9.8e+73): tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e+64) || !(x <= 9.8e+73)) tmp = Float64(3.0 * x); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e+64) || ~((x <= 9.8e+73))) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+64], N[Not[LessEqual[x, 9.8e+73]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+64} \lor \neg \left(x \leq 9.8 \cdot 10^{+73}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -8.99999999999999946e64 or 9.7999999999999998e73 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6469.2
Applied rewrites69.2%
if -8.99999999999999946e64 < x < 9.7999999999999998e73Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6451.3
Applied rewrites51.3%
Taylor expanded in x around 0
Applied rewrites43.1%
Applied rewrites43.1%
Final simplification53.4%
(FPCore (x y z) :precision binary64 (+ y y))
double code(double x, double y, double z) {
return y + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + y
end function
public static double code(double x, double y, double z) {
return y + y;
}
def code(x, y, z): return y + y
function code(x, y, z) return Float64(y + y) end
function tmp = code(x, y, z) tmp = y + y; end
code[x_, y_, z_] := N[(y + y), $MachinePrecision]
\begin{array}{l}
\\
y + y
\end{array}
Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6463.5
Applied rewrites63.5%
Taylor expanded in x around 0
Applied rewrites31.3%
Applied rewrites31.3%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))