
(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
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.02e-53) (fma 2.0 y z) (if (<= z 1.8e+67) (fma 3.0 x (+ y y)) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.02e-53) {
tmp = fma(2.0, y, z);
} else if (z <= 1.8e+67) {
tmp = fma(3.0, x, (y + y));
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.02e-53) tmp = fma(2.0, y, z); elseif (z <= 1.8e+67) tmp = fma(3.0, x, Float64(y + y)); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.02e-53], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[z, 1.8e+67], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.02 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if z < -2.02000000000000005e-53Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.3
Applied rewrites89.3%
if -2.02000000000000005e-53 < z < 1.7999999999999999e67Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6492.9
Applied rewrites92.9%
Taylor expanded in x around 0
Applied rewrites93.0%
Applied rewrites93.0%
if 1.7999999999999999e67 < z Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6490.4
Applied rewrites90.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.08e+17) (not (<= x 6.5e+125))) (fma 3.0 x z) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.08e+17) || !(x <= 6.5e+125)) {
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 <= -1.08e+17) || !(x <= 6.5e+125)) 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, -1.08e+17], N[Not[LessEqual[x, 6.5e+125]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.08 \cdot 10^{+17} \lor \neg \left(x \leq 6.5 \cdot 10^{+125}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.08e17 or 6.4999999999999999e125 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6485.1
Applied rewrites85.1%
if -1.08e17 < x < 6.4999999999999999e125Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.8
Applied rewrites90.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.32e+101) (not (<= x 1.38e+178))) (* 3.0 x) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.32e+101) || !(x <= 1.38e+178)) {
tmp = 3.0 * x;
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.32e+101) || !(x <= 1.38e+178)) tmp = Float64(3.0 * x); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.32e+101], N[Not[LessEqual[x, 1.38e+178]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+101} \lor \neg \left(x \leq 1.38 \cdot 10^{+178}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.32e101 or 1.37999999999999994e178 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6470.0
Applied rewrites70.0%
if -1.32e101 < x < 1.37999999999999994e178Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6486.4
Applied rewrites86.4%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.08e+17) (not (<= x 1.1e+132))) (* 3.0 x) (+ y y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.08e+17) || !(x <= 1.1e+132)) {
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 <= (-1.08d+17)) .or. (.not. (x <= 1.1d+132))) 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 <= -1.08e+17) || !(x <= 1.1e+132)) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.08e+17) or not (x <= 1.1e+132): tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.08e+17) || !(x <= 1.1e+132)) 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 <= -1.08e+17) || ~((x <= 1.1e+132))) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.08e+17], N[Not[LessEqual[x, 1.1e+132]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.08 \cdot 10^{+17} \lor \neg \left(x \leq 1.1 \cdot 10^{+132}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -1.08e17 or 1.09999999999999994e132 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6459.2
Applied rewrites59.2%
if -1.08e17 < x < 1.09999999999999994e132Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6458.4
Applied rewrites58.4%
Taylor expanded in x around 0
Applied rewrites49.9%
Applied rewrites49.9%
Final simplification53.5%
(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-+.f6464.3
Applied rewrites64.3%
Taylor expanded in x around 0
Applied rewrites36.7%
Applied rewrites36.7%
herbie shell --seed 2024324
(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))