
(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 (fma 2.0 (+ x y) (+ z x)))
double code(double x, double y, double z) {
return fma(2.0, (x + y), (z + x));
}
function code(x, y, z) return fma(2.0, Float64(x + y), Float64(z + x)) end
code[x_, y_, z_] := N[(2.0 * N[(x + y), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, x + y, z + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
count-2N/A
+-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+43) (fma 3.0 x (+ y y)) (if (<= x 9.5e+134) (+ (fma y 2.0 z) x) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+43) {
tmp = fma(3.0, x, (y + y));
} else if (x <= 9.5e+134) {
tmp = fma(y, 2.0, z) + x;
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+43) tmp = fma(3.0, x, Float64(y + y)); elseif (x <= 9.5e+134) tmp = Float64(fma(y, 2.0, z) + x); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+43], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.5e+134], N[(N[(y * 2.0 + z), $MachinePrecision] + x), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+43}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -4.20000000000000003e43Initial program 99.8%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
Applied rewrites88.4%
if -4.20000000000000003e43 < x < 9.5000000000000004e134Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6491.6
Applied rewrites91.6%
if 9.5000000000000004e134 < 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.f6492.2
Applied rewrites92.2%
(FPCore (x y z) :precision binary64 (if (<= x -7e+42) (fma 3.0 x (+ y y)) (if (<= x 4.8e+127) (fma y 2.0 z) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e+42) {
tmp = fma(3.0, x, (y + y));
} else if (x <= 4.8e+127) {
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 <= -7e+42) tmp = fma(3.0, x, Float64(y + y)); elseif (x <= 4.8e+127) tmp = fma(y, 2.0, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -7e+42], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.8e+127], N[(y * 2.0 + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -7.00000000000000047e42Initial program 99.8%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
Applied rewrites88.4%
if -7.00000000000000047e42 < x < 4.8000000000000004e127Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.6
Applied rewrites90.6%
if 4.8000000000000004e127 < 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.f6490.1
Applied rewrites90.1%
(FPCore (x y z) :precision binary64 (if (<= y -8e+30) (fma y 2.0 z) (if (<= y 3.9e-10) (fma 3.0 x z) (fma y 2.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+30) {
tmp = fma(y, 2.0, z);
} else if (y <= 3.9e-10) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(y, 2.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8e+30) tmp = fma(y, 2.0, z); elseif (y <= 3.9e-10) tmp = fma(3.0, x, z); else tmp = fma(y, 2.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8e+30], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[y, 3.9e-10], N[(3.0 * x + z), $MachinePrecision], N[(y * 2.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+30}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\end{array}
\end{array}
if y < -8.0000000000000002e30 or 3.9e-10 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.6
Applied rewrites88.6%
if -8.0000000000000002e30 < y < 3.9e-10Initial 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.8
Applied rewrites90.8%
(FPCore (x y z) :precision binary64 (if (<= y -1e+201) (+ y y) (if (<= y 3e+113) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e+201) {
tmp = y + y;
} else if (y <= 3e+113) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1e+201) tmp = Float64(y + y); elseif (y <= 3e+113) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1e+201], N[(y + y), $MachinePrecision], If[LessEqual[y, 3e+113], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+201}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -1.00000000000000004e201 or 3e113 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
Applied rewrites77.1%
if -1.00000000000000004e201 < y < 3e113Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6480.3
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e-7) (+ y y) (if (<= y 7.8e-7) (* 3.0 x) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-7) {
tmp = y + y;
} else if (y <= 7.8e-7) {
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 (y <= (-7.5d-7)) then
tmp = y + y
else if (y <= 7.8d-7) 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 (y <= -7.5e-7) {
tmp = y + y;
} else if (y <= 7.8e-7) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e-7: tmp = y + y elif y <= 7.8e-7: tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e-7) tmp = Float64(y + y); elseif (y <= 7.8e-7) 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 (y <= -7.5e-7) tmp = y + y; elseif (y <= 7.8e-7) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e-7], N[(y + y), $MachinePrecision], If[LessEqual[y, 7.8e-7], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-7}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-7}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -7.5000000000000002e-7 or 7.80000000000000049e-7 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6461.4
Applied rewrites61.4%
Applied rewrites61.4%
if -7.5000000000000002e-7 < y < 7.80000000000000049e-7Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6447.1
Applied rewrites47.1%
(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-*.f6438.2
Applied rewrites38.2%
Applied rewrites38.2%
herbie shell --seed 2024266
(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))