
(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 (+ (+ z (+ (+ (+ y x) y) x)) x))
double code(double x, double y, double z) {
return (z + (((y + x) + y) + x)) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z + (((y + x) + y) + x)) + x
end function
public static double code(double x, double y, double z) {
return (z + (((y + x) + y) + x)) + x;
}
def code(x, y, z): return (z + (((y + x) + y) + x)) + x
function code(x, y, z) return Float64(Float64(z + Float64(Float64(Float64(y + x) + y) + x)) + x) end
function tmp = code(x, y, z) tmp = (z + (((y + x) + y) + x)) + x; end
code[x_, y_, z_] := N[(N[(z + N[(N[(N[(y + x), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(z + \left(\left(\left(y + x\right) + y\right) + x\right)\right) + x
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.26e+14) (fma y 2.0 z) (if (<= z 6e+159) (fma 3.0 x (+ y y)) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.26e+14) {
tmp = fma(y, 2.0, z);
} else if (z <= 6e+159) {
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 <= -1.26e+14) tmp = fma(y, 2.0, z); elseif (z <= 6e+159) 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, -1.26e+14], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[z, 6e+159], 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 -1.26 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+159}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if z < -1.26e14Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6489.9
Applied rewrites89.9%
if -1.26e14 < z < 6.0000000000000004e159Initial 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-*.f6491.2
Applied rewrites91.2%
Applied rewrites91.2%
if 6.0000000000000004e159 < 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.f6495.7
Applied rewrites95.7%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e+59) (fma y 2.0 z) (if (<= y 1e+45) (fma 3.0 x z) (fma y 2.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e+59) {
tmp = fma(y, 2.0, z);
} else if (y <= 1e+45) {
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 <= -2.9e+59) tmp = fma(y, 2.0, z); elseif (y <= 1e+45) tmp = fma(3.0, x, z); else tmp = fma(y, 2.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.9e+59], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[y, 1e+45], N[(3.0 * x + z), $MachinePrecision], N[(y * 2.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+59}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;y \leq 10^{+45}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\end{array}
\end{array}
if y < -2.89999999999999991e59 or 9.9999999999999993e44 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.7
Applied rewrites82.7%
if -2.89999999999999991e59 < y < 9.9999999999999993e44Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6488.9
Applied rewrites88.9%
(FPCore (x y z) :precision binary64 (if (<= y -9e+142) (+ y y) (if (<= y 7.4e+154) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e+142) {
tmp = y + y;
} else if (y <= 7.4e+154) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -9e+142) tmp = Float64(y + y); elseif (y <= 7.4e+154) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -9e+142], N[(y + y), $MachinePrecision], If[LessEqual[y, 7.4e+154], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+142}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -8.9999999999999998e142 or 7.39999999999999989e154 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
Applied rewrites85.1%
if -8.9999999999999998e142 < y < 7.39999999999999989e154Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6482.8
Applied rewrites82.8%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e-6) (+ y y) (if (<= y 1.3e+45) (* 3.0 x) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-6) {
tmp = y + y;
} else if (y <= 1.3e+45) {
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 <= (-6.8d-6)) then
tmp = y + y
else if (y <= 1.3d+45) 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 <= -6.8e-6) {
tmp = y + y;
} else if (y <= 1.3e+45) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e-6: tmp = y + y elif y <= 1.3e+45: tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-6) tmp = Float64(y + y); elseif (y <= 1.3e+45) 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 <= -6.8e-6) tmp = y + y; elseif (y <= 1.3e+45) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-6], N[(y + y), $MachinePrecision], If[LessEqual[y, 1.3e+45], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-6}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+45}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -6.80000000000000012e-6 or 1.30000000000000004e45 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6458.3
Applied rewrites58.3%
Applied rewrites58.3%
if -6.80000000000000012e-6 < y < 1.30000000000000004e45Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6452.5
Applied rewrites52.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 y around inf
*-commutativeN/A
lower-*.f6434.7
Applied rewrites34.7%
Applied rewrites34.7%
herbie shell --seed 2024244
(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))