
(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 (+ (+ (+ z x) x) (fma 2.0 y x)))
double code(double x, double y, double z) {
return ((z + x) + x) + fma(2.0, y, x);
}
function code(x, y, z) return Float64(Float64(Float64(z + x) + x) + fma(2.0, y, x)) end
code[x_, y_, z_] := N[(N[(N[(z + x), $MachinePrecision] + x), $MachinePrecision] + N[(2.0 * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(z + x\right) + x\right) + \mathsf{fma}\left(2, y, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate-+l+N/A
lower-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z -4e+46) (fma y 2.0 z) (if (<= z 2e+48) (fma 3.0 x (+ y y)) (fma y 2.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+46) {
tmp = fma(y, 2.0, z);
} else if (z <= 2e+48) {
tmp = fma(3.0, x, (y + y));
} else {
tmp = fma(y, 2.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -4e+46) tmp = fma(y, 2.0, z); elseif (z <= 2e+48) tmp = fma(3.0, x, Float64(y + y)); else tmp = fma(y, 2.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -4e+46], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[z, 2e+48], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], N[(y * 2.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+48}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\end{array}
\end{array}
if z < -4e46 or 2.00000000000000009e48 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.1
Applied rewrites88.1%
if -4e46 < z < 2.00000000000000009e48Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.7
Applied rewrites93.7%
Applied rewrites93.7%
(FPCore (x y z) :precision binary64 (if (<= y -6.5e+64) (fma y 2.0 z) (if (<= y 1.75e-102) (fma 3.0 x z) (fma y 2.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e+64) {
tmp = fma(y, 2.0, z);
} else if (y <= 1.75e-102) {
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 <= -6.5e+64) tmp = fma(y, 2.0, z); elseif (y <= 1.75e-102) tmp = fma(3.0, x, z); else tmp = fma(y, 2.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6.5e+64], N[(y * 2.0 + z), $MachinePrecision], If[LessEqual[y, 1.75e-102], N[(3.0 * x + z), $MachinePrecision], N[(y * 2.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+64}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-102}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\end{array}
\end{array}
if y < -6.50000000000000007e64 or 1.74999999999999993e-102 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6484.7
Applied rewrites84.7%
if -6.50000000000000007e64 < y < 1.74999999999999993e-102Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6494.3
Applied rewrites94.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.75e+65) (+ y y) (if (<= y 6.5e+57) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.75e+65) {
tmp = y + y;
} else if (y <= 6.5e+57) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.75e+65) tmp = Float64(y + y); elseif (y <= 6.5e+57) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.75e+65], N[(y + y), $MachinePrecision], If[LessEqual[y, 6.5e+57], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+65}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -1.75e65 or 6.4999999999999997e57 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6471.4
Applied rewrites71.4%
Applied rewrites71.4%
if -1.75e65 < y < 6.4999999999999997e57Initial 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.4
Applied rewrites90.4%
(FPCore (x y z) :precision binary64 (if (<= y -6.5e+64) (+ y y) (if (<= y 1.22e-101) (* 3.0 x) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e+64) {
tmp = y + y;
} else if (y <= 1.22e-101) {
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.5d+64)) then
tmp = y + y
else if (y <= 1.22d-101) 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.5e+64) {
tmp = y + y;
} else if (y <= 1.22e-101) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.5e+64: tmp = y + y elif y <= 1.22e-101: tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.5e+64) tmp = Float64(y + y); elseif (y <= 1.22e-101) 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.5e+64) tmp = y + y; elseif (y <= 1.22e-101) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.5e+64], N[(y + y), $MachinePrecision], If[LessEqual[y, 1.22e-101], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+64}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-101}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -6.50000000000000007e64 or 1.2199999999999999e-101 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6464.8
Applied rewrites64.8%
Applied rewrites64.8%
if -6.50000000000000007e64 < y < 1.2199999999999999e-101Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6441.8
Applied rewrites41.8%
(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}
Initial program 99.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-*.f6440.7
Applied rewrites40.7%
Applied rewrites40.7%
herbie shell --seed 2024268
(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))