
(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 (<= z -1e+102) (fma 3.0 x z) (if (<= z 1.1e+31) (fma 3.0 x (+ y y)) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+102) {
tmp = fma(3.0, x, z);
} else if (z <= 1.1e+31) {
tmp = fma(3.0, x, (y + y));
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1e+102) tmp = fma(3.0, x, z); elseif (z <= 1.1e+31) tmp = fma(3.0, x, Float64(y + y)); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1e+102], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[z, 1.1e+31], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+31}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if z < -9.99999999999999977e101Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6490.1
Applied rewrites90.1%
if -9.99999999999999977e101 < z < 1.10000000000000005e31Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6491.0
Applied rewrites91.0%
Taylor expanded in x around 0
Applied rewrites91.1%
Applied rewrites91.1%
if 1.10000000000000005e31 < z Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6491.4
Applied rewrites91.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.04e+108) (not (<= y 7.6e+62))) (fma 2.0 y z) (fma 3.0 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.04e+108) || !(y <= 7.6e+62)) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.04e+108) || !(y <= 7.6e+62)) tmp = fma(2.0, y, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.04e+108], N[Not[LessEqual[y, 7.6e+62]], $MachinePrecision]], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{+108} \lor \neg \left(y \leq 7.6 \cdot 10^{+62}\right):\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if y < -1.04e108 or 7.59999999999999967e62 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.9
Applied rewrites87.9%
if -1.04e108 < y < 7.59999999999999967e62Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6490.0
Applied rewrites90.0%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e+94) (not (<= x 6.9e+204))) (* 3.0 x) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e+94) || !(x <= 6.9e+204)) {
tmp = 3.0 * x;
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1e+94) || !(x <= 6.9e+204)) tmp = Float64(3.0 * x); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e+94], N[Not[LessEqual[x, 6.9e+204]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+94} \lor \neg \left(x \leq 6.9 \cdot 10^{+204}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1e94 or 6.89999999999999999e204 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6479.1
Applied rewrites79.1%
if -1e94 < x < 6.89999999999999999e204Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6482.4
Applied rewrites82.4%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.04e+108) (not (<= y 1.05e+63))) (+ y y) (* 3.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.04e+108) || !(y <= 1.05e+63)) {
tmp = y + y;
} else {
tmp = 3.0 * 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.04d+108)) .or. (.not. (y <= 1.05d+63))) then
tmp = y + y
else
tmp = 3.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.04e+108) || !(y <= 1.05e+63)) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.04e+108) or not (y <= 1.05e+63): tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.04e+108) || !(y <= 1.05e+63)) tmp = Float64(y + y); else tmp = Float64(3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.04e+108) || ~((y <= 1.05e+63))) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.04e+108], N[Not[LessEqual[y, 1.05e+63]], $MachinePrecision]], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{+108} \lor \neg \left(y \leq 1.05 \cdot 10^{+63}\right):\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if y < -1.04e108 or 1.0500000000000001e63 < y Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6484.2
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites72.1%
Applied rewrites72.1%
if -1.04e108 < y < 1.0500000000000001e63Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6450.6
Applied rewrites50.6%
Final simplification58.2%
(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-+.f6468.2
Applied rewrites68.2%
Taylor expanded in x around 0
Applied rewrites33.0%
Applied rewrites33.0%
herbie shell --seed 2024329
(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))