
(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 9 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) (+ 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 -1.9e+159)
(* x 3.0)
(if (<= x -2.9e-196)
(+ x z)
(if (<= x 4.1e-144) (* 2.0 y) (if (<= x 8.5e+83) (+ x z) (* x 3.0))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+159) {
tmp = x * 3.0;
} else if (x <= -2.9e-196) {
tmp = x + z;
} else if (x <= 4.1e-144) {
tmp = 2.0 * y;
} else if (x <= 8.5e+83) {
tmp = x + z;
} 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.9d+159)) then
tmp = x * 3.0d0
else if (x <= (-2.9d-196)) then
tmp = x + z
else if (x <= 4.1d-144) then
tmp = 2.0d0 * y
else if (x <= 8.5d+83) then
tmp = x + z
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.9e+159) {
tmp = x * 3.0;
} else if (x <= -2.9e-196) {
tmp = x + z;
} else if (x <= 4.1e-144) {
tmp = 2.0 * y;
} else if (x <= 8.5e+83) {
tmp = x + z;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e+159: tmp = x * 3.0 elif x <= -2.9e-196: tmp = x + z elif x <= 4.1e-144: tmp = 2.0 * y elif x <= 8.5e+83: tmp = x + z else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+159) tmp = Float64(x * 3.0); elseif (x <= -2.9e-196) tmp = Float64(x + z); elseif (x <= 4.1e-144) tmp = Float64(2.0 * y); elseif (x <= 8.5e+83) tmp = Float64(x + z); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e+159) tmp = x * 3.0; elseif (x <= -2.9e-196) tmp = x + z; elseif (x <= 4.1e-144) tmp = 2.0 * y; elseif (x <= 8.5e+83) tmp = x + z; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+159], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -2.9e-196], N[(x + z), $MachinePrecision], If[LessEqual[x, 4.1e-144], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 8.5e+83], N[(x + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+159}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq -2.9 \cdot 10^{-196}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-144}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+83}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.89999999999999983e159 or 8.4999999999999995e83 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6474.3
Simplified74.3%
if -1.89999999999999983e159 < x < -2.89999999999999987e-196 or 4.1e-144 < x < 8.4999999999999995e83Initial program 100.0%
Taylor expanded in z around inf
Simplified52.8%
if -2.89999999999999987e-196 < x < 4.1e-144Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6461.4
Simplified61.4%
Final simplification62.2%
(FPCore (x y z) :precision binary64 (if (<= x -8.2e+98) (fma x 3.0 z) (if (<= x 1.3e+85) (fma 2.0 y z) (fma 2.0 (+ x y) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.2e+98) {
tmp = fma(x, 3.0, z);
} else if (x <= 1.3e+85) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(2.0, (x + y), x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -8.2e+98) tmp = fma(x, 3.0, z); elseif (x <= 1.3e+85) tmp = fma(2.0, y, z); else tmp = fma(2.0, Float64(x + y), x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -8.2e+98], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 1.3e+85], N[(2.0 * y + z), $MachinePrecision], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{+85}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\end{array}
\end{array}
if x < -8.2000000000000001e98Initial 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.f6485.5
Simplified85.5%
if -8.2000000000000001e98 < x < 1.30000000000000005e85Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6489.2
Simplified89.2%
if 1.30000000000000005e85 < x Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6487.6
Simplified87.6%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (<= x -4.5e+101) (fma x 3.0 z) (if (<= x 3.4e+86) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+101) {
tmp = fma(x, 3.0, z);
} else if (x <= 3.4e+86) {
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 <= -4.5e+101) tmp = fma(x, 3.0, z); elseif (x <= 3.4e+86) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.5e+101], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 3.4e+86], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -4.5000000000000002e101 or 3.3999999999999998e86 < 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.f6486.5
Simplified86.5%
if -4.5000000000000002e101 < x < 3.3999999999999998e86Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6489.3
Simplified89.3%
(FPCore (x y z) :precision binary64 (if (<= x -9.5e+179) (* x 3.0) (if (<= x 7.5e+113) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+179) {
tmp = x * 3.0;
} else if (x <= 7.5e+113) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -9.5e+179) tmp = Float64(x * 3.0); elseif (x <= 7.5e+113) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -9.5e+179], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 7.5e+113], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+179}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -9.5e179 or 7.5000000000000001e113 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6480.4
Simplified80.4%
if -9.5e179 < x < 7.5000000000000001e113Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6484.5
Simplified84.5%
(FPCore (x y z) :precision binary64 (if (<= y -7.4e-62) (* 2.0 y) (if (<= y 1.05e+118) (+ x z) (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.4e-62) {
tmp = 2.0 * y;
} else if (y <= 1.05e+118) {
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.4d-62)) then
tmp = 2.0d0 * y
else if (y <= 1.05d+118) 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.4e-62) {
tmp = 2.0 * y;
} else if (y <= 1.05e+118) {
tmp = x + z;
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.4e-62: tmp = 2.0 * y elif y <= 1.05e+118: tmp = x + z else: tmp = 2.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.4e-62) tmp = Float64(2.0 * y); elseif (y <= 1.05e+118) 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.4e-62) tmp = 2.0 * y; elseif (y <= 1.05e+118) tmp = x + z; else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.4e-62], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, 1.05e+118], N[(x + z), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-62}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+118}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if y < -7.3999999999999996e-62 or 1.05e118 < y Initial program 99.9%
Taylor expanded in y around inf
*-lowering-*.f6460.3
Simplified60.3%
if -7.3999999999999996e-62 < y < 1.05e118Initial program 99.9%
Taylor expanded in z around inf
Simplified52.1%
Final simplification55.7%
(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
Simplified38.7%
Final simplification38.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
Taylor expanded in z around inf
Simplified33.4%
(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 y around inf
*-lowering-*.f6438.5
Simplified38.5%
Taylor expanded in y around 0
Simplified8.2%
herbie shell --seed 2024199
(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))