
(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 12 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 3.0 x (fma 2.0 y z)))
double code(double x, double y, double z) {
return fma(3.0, x, fma(2.0, y, z));
}
function code(x, y, z) return fma(3.0, x, fma(2.0, y, z)) end
code[x_, y_, z_] := N[(3.0 * x + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3, x, \mathsf{fma}\left(2, y, z\right)\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.9
Applied egg-rr99.9%
+-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
associate-+r+N/A
associate-+l+N/A
distribute-rgt1-inN/A
metadata-evalN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.4e+71)
(* 3.0 x)
(if (<= x -1.35e-31)
(+ x z)
(if (<= x 4.8e-5) (* 2.0 y) (if (<= x 2.1e+98) (+ x z) (* 3.0 x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+71) {
tmp = 3.0 * x;
} else if (x <= -1.35e-31) {
tmp = x + z;
} else if (x <= 4.8e-5) {
tmp = 2.0 * y;
} else if (x <= 2.1e+98) {
tmp = x + z;
} else {
tmp = 3.0 * 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 <= (-2.4d+71)) then
tmp = 3.0d0 * x
else if (x <= (-1.35d-31)) then
tmp = x + z
else if (x <= 4.8d-5) then
tmp = 2.0d0 * y
else if (x <= 2.1d+98) then
tmp = x + z
else
tmp = 3.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+71) {
tmp = 3.0 * x;
} else if (x <= -1.35e-31) {
tmp = x + z;
} else if (x <= 4.8e-5) {
tmp = 2.0 * y;
} else if (x <= 2.1e+98) {
tmp = x + z;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e+71: tmp = 3.0 * x elif x <= -1.35e-31: tmp = x + z elif x <= 4.8e-5: tmp = 2.0 * y elif x <= 2.1e+98: tmp = x + z else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e+71) tmp = Float64(3.0 * x); elseif (x <= -1.35e-31) tmp = Float64(x + z); elseif (x <= 4.8e-5) tmp = Float64(2.0 * y); elseif (x <= 2.1e+98) tmp = Float64(x + z); else tmp = Float64(3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e+71) tmp = 3.0 * x; elseif (x <= -1.35e-31) tmp = x + z; elseif (x <= 4.8e-5) tmp = 2.0 * y; elseif (x <= 2.1e+98) tmp = x + z; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e+71], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, -1.35e-31], N[(x + z), $MachinePrecision], If[LessEqual[x, 4.8e-5], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 2.1e+98], N[(x + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+71}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq -1.35 \cdot 10^{-31}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+98}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -2.39999999999999981e71 or 2.10000000000000004e98 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6482.7
Simplified82.7%
if -2.39999999999999981e71 < x < -1.35000000000000007e-31 or 4.8000000000000001e-5 < x < 2.10000000000000004e98Initial program 99.9%
Taylor expanded in z around inf
Simplified59.7%
if -1.35000000000000007e-31 < x < 4.8000000000000001e-5Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6457.1
Simplified57.1%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (if (<= z -3.7e+76) (+ x (fma 2.0 y z)) (if (<= z 10500000000.0) (fma x 3.0 (* 2.0 y)) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e+76) {
tmp = x + fma(2.0, y, z);
} else if (z <= 10500000000.0) {
tmp = fma(x, 3.0, (2.0 * y));
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.7e+76) tmp = Float64(x + fma(2.0, y, z)); elseif (z <= 10500000000.0) tmp = fma(x, 3.0, Float64(2.0 * y)); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.7e+76], N[(x + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 10500000000.0], N[(x * 3.0 + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+76}:\\
\;\;\;\;x + \mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;z \leq 10500000000:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 2 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if z < -3.6999999999999999e76Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6495.2
Simplified95.2%
if -3.6999999999999999e76 < z < 1.05e10Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6492.6
Simplified92.6%
distribute-lft-inN/A
associate-+l+N/A
distribute-lft1-inN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6492.6
Applied egg-rr92.6%
if 1.05e10 < 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.f6492.6
Simplified92.6%
Final simplification93.0%
(FPCore (x y z) :precision binary64 (if (<= z -4.8e+79) (+ x (fma 2.0 y z)) (if (<= z 120000000000.0) (fma 2.0 (+ x y) x) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.8e+79) {
tmp = x + fma(2.0, y, z);
} else if (z <= 120000000000.0) {
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 <= -4.8e+79) tmp = Float64(x + fma(2.0, y, z)); elseif (z <= 120000000000.0) 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, -4.8e+79], N[(x + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 120000000000.0], 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 -4.8 \cdot 10^{+79}:\\
\;\;\;\;x + \mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;z \leq 120000000000:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if z < -4.79999999999999971e79Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6495.2
Simplified95.2%
if -4.79999999999999971e79 < z < 1.2e11Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6492.6
Simplified92.6%
if 1.2e11 < 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.f6492.6
Simplified92.6%
Final simplification93.0%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e+63) (fma x 3.0 z) (if (<= x 7.5e+20) (+ x (fma 2.0 y z)) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e+63) {
tmp = fma(x, 3.0, z);
} else if (x <= 7.5e+20) {
tmp = x + fma(2.0, y, z);
} else {
tmp = fma(x, 3.0, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.5e+63) tmp = fma(x, 3.0, z); elseif (x <= 7.5e+20) tmp = Float64(x + fma(2.0, y, z)); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.5e+63], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 7.5e+20], N[(x + N[(2.0 * y + z), $MachinePrecision]), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+63}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+20}:\\
\;\;\;\;x + \mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -2.50000000000000005e63 or 7.5e20 < x 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.f6490.6
Simplified90.6%
if -2.50000000000000005e63 < x < 7.5e20Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6492.1
Simplified92.1%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (<= x -2.3e+40) (fma x 3.0 z) (if (<= x 2.6e+20) (fma 2.0 y z) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.3e+40) {
tmp = fma(x, 3.0, z);
} else if (x <= 2.6e+20) {
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 <= -2.3e+40) tmp = fma(x, 3.0, z); elseif (x <= 2.6e+20) tmp = fma(2.0, y, z); else tmp = fma(x, 3.0, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.3e+40], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 2.6e+20], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+40}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if x < -2.29999999999999994e40 or 2.6e20 < x 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.f6489.4
Simplified89.4%
if -2.29999999999999994e40 < x < 2.6e20Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6491.9
Simplified91.9%
(FPCore (x y z) :precision binary64 (if (<= x -3.45e+71) (* 3.0 x) (if (<= x 1.25e+92) (fma 2.0 y z) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.45e+71) {
tmp = 3.0 * x;
} else if (x <= 1.25e+92) {
tmp = fma(2.0, y, z);
} else {
tmp = 3.0 * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.45e+71) tmp = Float64(3.0 * x); elseif (x <= 1.25e+92) tmp = fma(2.0, y, z); else tmp = Float64(3.0 * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.45e+71], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 1.25e+92], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.45 \cdot 10^{+71}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+92}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -3.44999999999999987e71 or 1.25000000000000005e92 < x Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6482.0
Simplified82.0%
if -3.44999999999999987e71 < x < 1.25000000000000005e92Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6487.7
Simplified87.7%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+100) (+ x z) (if (<= z 3.8e+31) (* 2.0 y) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+100) {
tmp = x + z;
} else if (z <= 3.8e+31) {
tmp = 2.0 * y;
} 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.4d+100)) then
tmp = x + z
else if (z <= 3.8d+31) then
tmp = 2.0d0 * y
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.4e+100) {
tmp = x + z;
} else if (z <= 3.8e+31) {
tmp = 2.0 * y;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+100: tmp = x + z elif z <= 3.8e+31: tmp = 2.0 * y else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+100) tmp = Float64(x + z); elseif (z <= 3.8e+31) tmp = Float64(2.0 * y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+100) tmp = x + z; elseif (z <= 3.8e+31) tmp = 2.0 * y; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+100], N[(x + z), $MachinePrecision], If[LessEqual[z, 3.8e+31], N[(2.0 * y), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+100}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{+31}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -1.3999999999999999e100 or 3.8000000000000001e31 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified70.8%
if -1.3999999999999999e100 < z < 3.8000000000000001e31Initial program 99.9%
Taylor expanded in y around inf
*-lowering-*.f6446.9
Simplified46.9%
Final simplification55.8%
(FPCore (x y z) :precision binary64 (+ z (fma 2.0 (+ x y) x)))
double code(double x, double y, double z) {
return z + fma(2.0, (x + y), x);
}
function code(x, y, z) return Float64(z + fma(2.0, Float64(x + y), x)) end
code[x_, y_, z_] := N[(z + N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \mathsf{fma}\left(2, x + y, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
associate-+l+N/A
+-commutativeN/A
count-2N/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f6499.9
Applied egg-rr99.9%
(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.3%
Final simplification37.3%
(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
Simplified32.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 y around inf
*-lowering-*.f6440.4
Simplified40.4%
Taylor expanded in y around 0
Simplified8.2%
herbie shell --seed 2024204
(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))