
(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 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 (<= z -5e+118)
(+ x z)
(if (<= z -7.1e+34)
(* x 3.0)
(if (<= z 6.2e-23) (fma 2.0 y x) (if (<= z 3.2e+61) (* x 3.0) (+ x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e+118) {
tmp = x + z;
} else if (z <= -7.1e+34) {
tmp = x * 3.0;
} else if (z <= 6.2e-23) {
tmp = fma(2.0, y, x);
} else if (z <= 3.2e+61) {
tmp = x * 3.0;
} else {
tmp = x + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5e+118) tmp = Float64(x + z); elseif (z <= -7.1e+34) tmp = Float64(x * 3.0); elseif (z <= 6.2e-23) tmp = fma(2.0, y, x); elseif (z <= 3.2e+61) tmp = Float64(x * 3.0); else tmp = Float64(x + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5e+118], N[(x + z), $MachinePrecision], If[LessEqual[z, -7.1e+34], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 6.2e-23], N[(2.0 * y + x), $MachinePrecision], If[LessEqual[z, 3.2e+61], N[(x * 3.0), $MachinePrecision], N[(x + z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+118}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -7.1 \cdot 10^{+34}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(2, y, x\right)\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+61}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -4.99999999999999972e118 or 3.1999999999999998e61 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified70.1%
if -4.99999999999999972e118 < z < -7.09999999999999956e34 or 6.1999999999999998e-23 < z < 3.1999999999999998e61Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6462.7
Simplified62.7%
if -7.09999999999999956e34 < z < 6.1999999999999998e-23Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6491.1
Simplified91.1%
Taylor expanded in y around inf
Simplified61.1%
Final simplification64.6%
(FPCore (x y z)
:precision binary64
(if (<= z -1.95e+117)
(+ x z)
(if (<= z -5.8e+32)
(* x 3.0)
(if (<= z 1.7e-19) (* 2.0 y) (if (<= z 5.2e+55) (* x 3.0) (+ x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+117) {
tmp = x + z;
} else if (z <= -5.8e+32) {
tmp = x * 3.0;
} else if (z <= 1.7e-19) {
tmp = 2.0 * y;
} else if (z <= 5.2e+55) {
tmp = x * 3.0;
} else {
tmp = x + z;
}
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 (z <= (-1.95d+117)) then
tmp = x + z
else if (z <= (-5.8d+32)) then
tmp = x * 3.0d0
else if (z <= 1.7d-19) then
tmp = 2.0d0 * y
else if (z <= 5.2d+55) then
tmp = x * 3.0d0
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+117) {
tmp = x + z;
} else if (z <= -5.8e+32) {
tmp = x * 3.0;
} else if (z <= 1.7e-19) {
tmp = 2.0 * y;
} else if (z <= 5.2e+55) {
tmp = x * 3.0;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+117: tmp = x + z elif z <= -5.8e+32: tmp = x * 3.0 elif z <= 1.7e-19: tmp = 2.0 * y elif z <= 5.2e+55: tmp = x * 3.0 else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+117) tmp = Float64(x + z); elseif (z <= -5.8e+32) tmp = Float64(x * 3.0); elseif (z <= 1.7e-19) tmp = Float64(2.0 * y); elseif (z <= 5.2e+55) tmp = Float64(x * 3.0); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+117) tmp = x + z; elseif (z <= -5.8e+32) tmp = x * 3.0; elseif (z <= 1.7e-19) tmp = 2.0 * y; elseif (z <= 5.2e+55) tmp = x * 3.0; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+117], N[(x + z), $MachinePrecision], If[LessEqual[z, -5.8e+32], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 1.7e-19], N[(2.0 * y), $MachinePrecision], If[LessEqual[z, 5.2e+55], N[(x * 3.0), $MachinePrecision], N[(x + z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+117}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{+32}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-19}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+55}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -1.94999999999999995e117 or 5.2e55 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified70.1%
if -1.94999999999999995e117 < z < -5.80000000000000006e32 or 1.7000000000000001e-19 < z < 5.2e55Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6462.7
Simplified62.7%
if -5.80000000000000006e32 < z < 1.7000000000000001e-19Initial 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%
Taylor expanded in y around inf
*-lowering-*.f6455.9
Simplified55.9%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.35e+35) (fma x 3.0 z) (if (<= z 6.4e-24) (fma 3.0 x (* 2.0 y)) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.35e+35) {
tmp = fma(x, 3.0, z);
} else if (z <= 6.4e-24) {
tmp = fma(3.0, x, (2.0 * y));
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.35e+35) tmp = fma(x, 3.0, z); elseif (z <= 6.4e-24) tmp = fma(3.0, x, Float64(2.0 * y)); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.35e+35], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[z, 6.4e-24], N[(3.0 * x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(3, x, 2 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if z < -1.35000000000000001e35 or 6.40000000000000025e-24 < z Initial program 99.9%
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.1
Simplified84.1%
if -1.35000000000000001e35 < z < 6.40000000000000025e-24Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6491.8
Simplified91.8%
+-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6491.8
Applied egg-rr91.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e+33) (fma x 3.0 z) (if (<= z 6.4e-24) (fma 2.0 (+ x y) x) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+33) {
tmp = fma(x, 3.0, z);
} else if (z <= 6.4e-24) {
tmp = fma(2.0, (x + y), x);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+33) tmp = fma(x, 3.0, z); elseif (z <= 6.4e-24) tmp = fma(2.0, Float64(x + y), x); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+33], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[z, 6.4e-24], N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+33}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if z < -6.59999999999999953e33 or 6.40000000000000025e-24 < z Initial program 99.9%
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.1
Simplified84.1%
if -6.59999999999999953e33 < z < 6.40000000000000025e-24Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6491.8
Simplified91.8%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.8e+93) (fma 2.0 y z) (if (<= y 2.4e+87) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e+93) {
tmp = fma(2.0, y, z);
} else if (y <= 2.4e+87) {
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.8e+93) tmp = fma(2.0, y, z); elseif (y <= 2.4e+87) 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.8e+93], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 2.4e+87], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+93}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+87}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -1.8e93 or 2.39999999999999981e87 < y Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6487.8
Simplified87.8%
if -1.8e93 < y < 2.39999999999999981e87Initial program 99.9%
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.1
Simplified86.1%
(FPCore (x y z) :precision binary64 (if (<= x -4.1e+147) (* x 3.0) (if (<= x 2.8e+187) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.1e+147) {
tmp = x * 3.0;
} else if (x <= 2.8e+187) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.1e+147) tmp = Float64(x * 3.0); elseif (x <= 2.8e+187) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.1e+147], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 2.8e+187], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+147}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+187}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -4.09999999999999966e147 or 2.79999999999999989e187 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6475.9
Simplified75.9%
if -4.09999999999999966e147 < x < 2.79999999999999989e187Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6483.2
Simplified83.2%
(FPCore (x y z) :precision binary64 (if (<= y -7e+59) (* 2.0 y) (if (<= y 1.8e+82) (+ x z) (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+59) {
tmp = 2.0 * y;
} else if (y <= 1.8e+82) {
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 <= (-7d+59)) then
tmp = 2.0d0 * y
else if (y <= 1.8d+82) 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 <= -7e+59) {
tmp = 2.0 * y;
} else if (y <= 1.8e+82) {
tmp = x + z;
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+59: tmp = 2.0 * y elif y <= 1.8e+82: tmp = x + z else: tmp = 2.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+59) tmp = Float64(2.0 * y); elseif (y <= 1.8e+82) 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 <= -7e+59) tmp = 2.0 * y; elseif (y <= 1.8e+82) tmp = x + z; else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+59], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, 1.8e+82], N[(x + z), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+59}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+82}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if y < -7e59 or 1.80000000000000007e82 < y Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in y around inf
*-lowering-*.f6470.3
Simplified70.3%
if -7e59 < y < 1.80000000000000007e82Initial program 99.9%
Taylor expanded in z around inf
Simplified51.1%
Final simplification58.8%
(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
Simplified37.8%
Final simplification37.8%
(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.0%
(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
Simplified37.8%
Taylor expanded in z around 0
Simplified7.7%
herbie shell --seed 2024198
(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))