
(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 x 3.0 (fma 2.0 y z)))
double code(double x, double y, double z) {
return fma(x, 3.0, fma(2.0, y, z));
}
function code(x, y, z) return fma(x, 3.0, fma(2.0, y, z)) end
code[x_, y_, z_] := N[(x * 3.0 + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3, \mathsf{fma}\left(2, y, z\right)\right)
\end{array}
Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e+16) (fma y 2.0 z) (if (<= z 2.15e+94) (fma x 3.0 (+ y y)) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+16) {
tmp = fma(y, 2.0, z);
} else if (z <= 2.15e+94) {
tmp = fma(x, 3.0, (y + y));
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+16) tmp = fma(y, 2.0, z); elseif (z <= 2.15e+94) tmp = fma(x, 3.0, Float64(y + y)); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+16], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[z, 2.15e+94], N[(x * 3.0 + N[(y + y), $MachinePrecision]), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+94}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if z < -2.7e16Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.4
Applied rewrites87.4%
if -2.7e16 < z < 2.15e94Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites93.1%
Applied rewrites93.1%
if 2.15e94 < 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.f6487.9
Applied rewrites87.9%
(FPCore (x y z) :precision binary64 (if (<= x -8.5e+175) (fma 3.0 x z) (if (<= x 2.8e+52) (fma y 2.0 z) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.5e+175) {
tmp = fma(3.0, x, z);
} else if (x <= 2.8e+52) {
tmp = fma(y, 2.0, z);
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -8.5e+175) tmp = fma(3.0, x, z); elseif (x <= 2.8e+52) tmp = fma(y, 2.0, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -8.5e+175], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 2.8e+52], N[(y * 2.0 + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{+175}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+52}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -8.50000000000000034e175 or 2.8e52 < 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.f6487.2
Applied rewrites87.2%
if -8.50000000000000034e175 < x < 2.8e52Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6486.5
Applied rewrites86.5%
(FPCore (x y z) :precision binary64 (if (<= y -3.1e+70) (+ y y) (if (<= y 7.6e+140) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+70) {
tmp = y + y;
} else if (y <= 7.6e+140) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -3.1e+70) tmp = Float64(y + y); elseif (y <= 7.6e+140) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -3.1e+70], N[(y + y), $MachinePrecision], If[LessEqual[y, 7.6e+140], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+70}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+140}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -3.1000000000000003e70 or 7.6000000000000002e140 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6470.7
Applied rewrites70.7%
Applied rewrites70.7%
if -3.1000000000000003e70 < y < 7.6000000000000002e140Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6485.8
Applied rewrites85.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e+140) (* 3.0 x) (if (<= x 2.7e+52) (+ y y) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+140) {
tmp = 3.0 * x;
} else if (x <= 2.7e+52) {
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 (x <= (-1.05d+140)) then
tmp = 3.0d0 * x
else if (x <= 2.7d+52) 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 (x <= -1.05e+140) {
tmp = 3.0 * x;
} else if (x <= 2.7e+52) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e+140: tmp = 3.0 * x elif x <= 2.7e+52: tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e+140) tmp = Float64(3.0 * x); elseif (x <= 2.7e+52) 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 (x <= -1.05e+140) tmp = 3.0 * x; elseif (x <= 2.7e+52) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e+140], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 2.7e+52], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+140}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+52}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -1.0500000000000001e140 or 2.7e52 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6471.7
Applied rewrites71.7%
if -1.0500000000000001e140 < x < 2.7e52Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6448.9
Applied rewrites48.9%
Applied rewrites48.9%
(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 y around inf
*-commutativeN/A
lower-*.f6435.0
Applied rewrites35.0%
Applied rewrites35.0%
herbie shell --seed 2024235
(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))