
(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 11 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%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.7
Applied egg-rr99.7%
Taylor expanded in x around -inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
distribute-frac-neg2N/A
mul-1-negN/A
remove-double-negN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f6482.0
Simplified82.0%
distribute-lft-inN/A
*-commutativeN/A
div-invN/A
associate-*l*N/A
lft-mult-inverseN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= z -4.1e+132) (fma x 3.0 z) (if (<= z 1.4e+133) (fma 2.0 (+ x y) x) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.1e+132) {
tmp = fma(x, 3.0, z);
} else if (z <= 1.4e+133) {
tmp = fma(2.0, (x + y), x);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -4.1e+132) tmp = fma(x, 3.0, z); elseif (z <= 1.4e+133) tmp = fma(2.0, Float64(x + y), x); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -4.1e+132], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[z, 1.4e+133], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+132}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+133}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if z < -4.09999999999999992e132Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
accelerator-lowering-fma.f6484.7
Simplified84.7%
if -4.09999999999999992e132 < z < 1.40000000000000008e133Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6493.3
Simplified93.3%
if 1.40000000000000008e133 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6494.5
Simplified94.5%
Final simplification92.6%
(FPCore (x y z) :precision binary64 (if (<= x -7.2e+46) (fma x 3.0 z) (if (<= x 90000000.0) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.2e+46) {
tmp = fma(x, 3.0, z);
} else if (x <= 90000000.0) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -7.2e+46) tmp = fma(x, 3.0, z); elseif (x <= 90000000.0) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+46], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 90000000.0], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 90000000:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -7.1999999999999997e46 or 9e7 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
accelerator-lowering-fma.f6483.7
Simplified83.7%
if -7.1999999999999997e46 < x < 9e7Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6492.7
Simplified92.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.2e+127) (* x 3.0) (if (<= x 7e+119) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+127) {
tmp = x * 3.0;
} else if (x <= 7e+119) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.2e+127) tmp = Float64(x * 3.0); elseif (x <= 7e+119) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.2e+127], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 7e+119], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+127}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+119}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.2000000000000001e127 or 7.0000000000000001e119 < x Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6485.2
Simplified85.2%
if -1.2000000000000001e127 < x < 7.0000000000000001e119Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6482.9
Simplified82.9%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e-83) (fma 2.0 y x) (if (<= y 2.2e+163) (* x 3.0) (fma 2.0 y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-83) {
tmp = fma(2.0, y, x);
} else if (y <= 2.2e+163) {
tmp = x * 3.0;
} else {
tmp = fma(2.0, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -7.5e-83) tmp = fma(2.0, y, x); elseif (y <= 2.2e+163) tmp = Float64(x * 3.0); else tmp = fma(2.0, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -7.5e-83], N[(2.0 * y + x), $MachinePrecision], If[LessEqual[y, 2.2e+163], N[(x * 3.0), $MachinePrecision], N[(2.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-83}:\\
\;\;\;\;\mathsf{fma}\left(2, y, x\right)\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+163}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, x\right)\\
\end{array}
\end{array}
if y < -7.4999999999999997e-83 or 2.19999999999999986e163 < y Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6488.6
Simplified88.6%
Taylor expanded in y around inf
Simplified72.1%
if -7.4999999999999997e-83 < y < 2.19999999999999986e163Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6461.3
Simplified61.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.8e+37) (* x 3.0) (if (<= x 112000000.0) (* 2.0 y) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+37) {
tmp = x * 3.0;
} else if (x <= 112000000.0) {
tmp = 2.0 * y;
} else {
tmp = x * 3.0;
}
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.8d+37)) then
tmp = x * 3.0d0
else if (x <= 112000000.0d0) then
tmp = 2.0d0 * y
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+37) {
tmp = x * 3.0;
} else if (x <= 112000000.0) {
tmp = 2.0 * y;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e+37: tmp = x * 3.0 elif x <= 112000000.0: tmp = 2.0 * y else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e+37) tmp = Float64(x * 3.0); elseif (x <= 112000000.0) tmp = Float64(2.0 * y); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e+37) tmp = x * 3.0; elseif (x <= 112000000.0) tmp = 2.0 * y; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+37], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 112000000.0], N[(2.0 * y), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+37}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 112000000:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.79999999999999999e37 or 1.12e8 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6471.8
Simplified71.8%
if -1.79999999999999999e37 < x < 1.12e8Initial program 100.0%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around inf
*-lowering-*.f6458.2
Simplified58.2%
(FPCore (x y z) :precision binary64 (if (<= y -7.5e-83) (* 2.0 y) (if (<= y 1.95e+116) (+ x z) (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-83) {
tmp = 2.0 * y;
} else if (y <= 1.95e+116) {
tmp = x + z;
} else {
tmp = 2.0 * 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-83)) then
tmp = 2.0d0 * y
else if (y <= 1.95d+116) then
tmp = x + z
else
tmp = 2.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e-83) {
tmp = 2.0 * y;
} else if (y <= 1.95e+116) {
tmp = x + z;
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e-83: tmp = 2.0 * y elif y <= 1.95e+116: tmp = x + z else: tmp = 2.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e-83) tmp = Float64(2.0 * y); elseif (y <= 1.95e+116) tmp = Float64(x + z); else tmp = Float64(2.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.5e-83) tmp = 2.0 * y; elseif (y <= 1.95e+116) tmp = x + z; else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e-83], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, 1.95e+116], N[(x + z), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-83}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+116}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if y < -7.4999999999999997e-83 or 1.95000000000000016e116 < y Initial program 99.9%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.7
Applied egg-rr99.7%
Taylor expanded in y around inf
*-lowering-*.f6466.0
Simplified66.0%
if -7.4999999999999997e-83 < y < 1.95000000000000016e116Initial program 99.8%
Taylor expanded in z around inf
Simplified43.5%
Final simplification54.4%
(FPCore (x y z) :precision binary64 (fma 2.0 (+ x y) (+ x z)))
double code(double x, double y, double z) {
return fma(2.0, (x + y), (x + z));
}
function code(x, y, z) return fma(2.0, Float64(x + y), Float64(x + z)) end
code[x_, y_, z_] := N[(2.0 * N[(x + y), $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, x + y, x + z\right)
\end{array}
Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
+-lowering-+.f6499.9
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (if (<= x 3e+146) z x))
double code(double x, double y, double z) {
double tmp;
if (x <= 3e+146) {
tmp = z;
} else {
tmp = 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 <= 3d+146) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 3e+146) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 3e+146: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= 3e+146) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 3e+146) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 3e+146], z, x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3 \cdot 10^{+146}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < 3.00000000000000002e146Initial program 99.9%
Taylor expanded in z around inf
Simplified28.4%
if 3.00000000000000002e146 < x Initial program 99.7%
Taylor expanded in z around inf
Simplified17.3%
Taylor expanded in z around 0
Simplified17.3%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in z around inf
Simplified30.6%
Final simplification30.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in z around inf
Simplified30.6%
Taylor expanded in z around 0
Simplified9.4%
herbie shell --seed 2024195
(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))