
(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 7 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 (+ x (+ (+ x (+ y (+ x y))) z)))
double code(double x, double y, double z) {
return x + ((x + (y + (x + 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 + ((x + (y + (x + y))) + z)
end function
public static double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
def code(x, y, z): return x + ((x + (y + (x + y))) + z)
function code(x, y, z) return Float64(x + Float64(Float64(x + Float64(y + Float64(x + y))) + z)) end
function tmp = code(x, y, z) tmp = x + ((x + (y + (x + y))) + z); end
code[x_, y_, z_] := N[(x + N[(N[(x + N[(y + N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(x + \left(y + \left(x + y\right)\right)\right) + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e+146) (fma 3.0 x (* y 2.0)) (if (<= x 27500000.0) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+146) {
tmp = fma(3.0, x, (y * 2.0));
} else if (x <= 27500000.0) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+146) tmp = fma(3.0, x, Float64(y * 2.0)); elseif (x <= 27500000.0) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+146], N[(3.0 * x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 27500000.0], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y \cdot 2\right)\\
\mathbf{elif}\;x \leq 27500000:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -1.65000000000000008e146Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6497.4
Simplified97.4%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f6459.2
Simplified59.2%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
lower-*.f6497.8
Simplified97.8%
if -1.65000000000000008e146 < x < 2.75e7Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.8
Simplified90.8%
if 2.75e7 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6492.9
Simplified92.9%
Final simplification92.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e+146) (fma 2.0 (+ x y) x) (if (<= x 27500000.0) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+146) {
tmp = fma(2.0, (x + y), x);
} else if (x <= 27500000.0) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+146) tmp = fma(2.0, Float64(x + y), x); elseif (x <= 27500000.0) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+146], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 27500000.0], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{elif}\;x \leq 27500000:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -1.65000000000000008e146Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6497.4
Simplified97.4%
if -1.65000000000000008e146 < x < 2.75e7Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.8
Simplified90.8%
if 2.75e7 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6492.9
Simplified92.9%
Final simplification92.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e+201) (fma x 3.0 z) (if (<= x 27500000.0) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+201) {
tmp = fma(x, 3.0, z);
} else if (x <= 27500000.0) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+201) tmp = fma(x, 3.0, z); elseif (x <= 27500000.0) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+201], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 27500000.0], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+201}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 27500000:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -1.89999999999999998e201 or 2.75e7 < x Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6492.0
Simplified92.0%
if -1.89999999999999998e201 < x < 2.75e7Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.6
Simplified89.6%
(FPCore (x y z) :precision binary64 (if (<= x -2.12e+201) (* x 3.0) (if (<= x 4.6e+98) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.12e+201) {
tmp = x * 3.0;
} else if (x <= 4.6e+98) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.12e+201) tmp = Float64(x * 3.0); elseif (x <= 4.6e+98) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.12e+201], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 4.6e+98], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.12 \cdot 10^{+201}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -2.11999999999999998e201 or 4.60000000000000026e98 < x Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6477.2
Simplified77.2%
if -2.11999999999999998e201 < x < 4.60000000000000026e98Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.2
Simplified87.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e+201) (* x 3.0) (if (<= x 27500000.0) (* y 2.0) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+201) {
tmp = x * 3.0;
} else if (x <= 27500000.0) {
tmp = y * 2.0;
} else {
tmp = x * 3.0;
}
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.9d+201)) then
tmp = x * 3.0d0
else if (x <= 27500000.0d0) then
tmp = y * 2.0d0
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+201) {
tmp = x * 3.0;
} else if (x <= 27500000.0) {
tmp = y * 2.0;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e+201: tmp = x * 3.0 elif x <= 27500000.0: tmp = y * 2.0 else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+201) tmp = Float64(x * 3.0); elseif (x <= 27500000.0) tmp = Float64(y * 2.0); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e+201) tmp = x * 3.0; elseif (x <= 27500000.0) tmp = y * 2.0; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+201], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 27500000.0], N[(y * 2.0), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+201}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 27500000:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.89999999999999998e201 or 2.75e7 < x Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6472.1
Simplified72.1%
if -1.89999999999999998e201 < x < 2.75e7Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6444.5
Simplified44.5%
Final simplification54.2%
(FPCore (x y z) :precision binary64 (* y 2.0))
double code(double x, double y, double z) {
return y * 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * 2.0d0
end function
public static double code(double x, double y, double z) {
return y * 2.0;
}
def code(x, y, z): return y * 2.0
function code(x, y, z) return Float64(y * 2.0) end
function tmp = code(x, y, z) tmp = y * 2.0; end
code[x_, y_, z_] := N[(y * 2.0), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 2
\end{array}
Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6432.1
Simplified32.1%
Final simplification32.1%
herbie shell --seed 2024207
(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))