
(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 (+ 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 (<= y -5.2e-24) (fma 2.0 (+ x y) x) (if (<= y 5.2e+56) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e-24) {
tmp = fma(2.0, (x + y), x);
} else if (y <= 5.2e+56) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -5.2e-24) tmp = fma(2.0, Float64(x + y), x); elseif (y <= 5.2e+56) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -5.2e-24], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 5.2e+56], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+56}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -5.2e-24Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6485.1
Applied rewrites85.1%
if -5.2e-24 < y < 5.20000000000000022e56Initial 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.f6495.7
Applied rewrites95.7%
if 5.20000000000000022e56 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.2
Applied rewrites90.2%
Final simplification91.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-28) (fma 2.0 y z) (if (<= y 5.2e+56) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-28) {
tmp = fma(2.0, y, z);
} else if (y <= 5.2e+56) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-28) tmp = fma(2.0, y, z); elseif (y <= 5.2e+56) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-28], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 5.2e+56], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+56}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -1.90000000000000005e-28 or 5.20000000000000022e56 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6484.4
Applied rewrites84.4%
if -1.90000000000000005e-28 < y < 5.20000000000000022e56Initial 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.f6495.7
Applied rewrites95.7%
(FPCore (x y z) :precision binary64 (if (<= x -3.6e+169) (* x 3.0) (if (<= x 8.5e+161) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e+169) {
tmp = x * 3.0;
} else if (x <= 8.5e+161) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.6e+169) tmp = Float64(x * 3.0); elseif (x <= 8.5e+161) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.6e+169], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 8.5e+161], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+169}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+161}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -3.6000000000000001e169 or 8.50000000000000007e161 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6480.0
Applied rewrites80.0%
if -3.6000000000000001e169 < x < 8.50000000000000007e161Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6483.9
Applied rewrites83.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.9e-28) (+ y y) (if (<= y 5.2e+56) (* x 3.0) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-28) {
tmp = y + y;
} else if (y <= 5.2e+56) {
tmp = x * 3.0;
} 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 <= (-1.9d-28)) then
tmp = y + y
else if (y <= 5.2d+56) then
tmp = x * 3.0d0
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-28) {
tmp = y + y;
} else if (y <= 5.2e+56) {
tmp = x * 3.0;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-28: tmp = y + y elif y <= 5.2e+56: tmp = x * 3.0 else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-28) tmp = Float64(y + y); elseif (y <= 5.2e+56) tmp = Float64(x * 3.0); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e-28) tmp = y + y; elseif (y <= 5.2e+56) tmp = x * 3.0; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-28], N[(y + y), $MachinePrecision], If[LessEqual[y, 5.2e+56], N[(x * 3.0), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+56}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -1.90000000000000005e-28 or 5.20000000000000022e56 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6470.8
Applied rewrites70.8%
Applied rewrites70.8%
if -1.90000000000000005e-28 < y < 5.20000000000000022e56Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6440.3
Applied rewrites40.3%
(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
lower-*.f6436.0
Applied rewrites36.0%
Applied rewrites36.0%
herbie shell --seed 2024238
(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))