
(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 10 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 (+ x (+ (+ x (+ y (+ x y))) z)))
double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + 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 + ((x + (y + (x + y))) + z)
end function
public static double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
def code(x, y, z): return x + ((x + (y + (x + y))) + z)
function code(x, y, z) return Float64(x + Float64(Float64(x + Float64(y + Float64(x + y))) + z)) end
function tmp = code(x, y, z) tmp = x + ((x + (y + (x + y))) + z); end
code[x_, y_, z_] := N[(x + N[(N[(x + N[(y + N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(x + \left(y + \left(x + y\right)\right)\right) + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= z -2.2e-7)
(+ x z)
(if (<= z -1.55e-287)
(fma 2.0 y x)
(if (<= z 2.95e+23) (* x 3.0) (+ x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-7) {
tmp = x + z;
} else if (z <= -1.55e-287) {
tmp = fma(2.0, y, x);
} else if (z <= 2.95e+23) {
tmp = x * 3.0;
} else {
tmp = x + z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-7) tmp = Float64(x + z); elseif (z <= -1.55e-287) tmp = fma(2.0, y, x); elseif (z <= 2.95e+23) tmp = Float64(x * 3.0); else tmp = Float64(x + z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-7], N[(x + z), $MachinePrecision], If[LessEqual[z, -1.55e-287], N[(2.0 * y + x), $MachinePrecision], If[LessEqual[z, 2.95e+23], N[(x * 3.0), $MachinePrecision], N[(x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-7}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -1.55 \cdot 10^{-287}:\\
\;\;\;\;\mathsf{fma}\left(2, y, x\right)\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+23}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -2.2000000000000001e-7 or 2.94999999999999994e23 < z Initial program 99.9%
Taylor expanded in z around inf
Simplified63.3%
if -2.2000000000000001e-7 < z < -1.55e-287Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6494.5
Simplified94.5%
Taylor expanded in y around inf
Simplified70.3%
if -1.55e-287 < z < 2.94999999999999994e23Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6457.8
Simplified57.8%
Final simplification63.1%
(FPCore (x y z) :precision binary64 (if (<= z -6.1e-9) (+ x z) (if (<= z -1.75e-286) (* y 2.0) (if (<= z 2.9e+23) (* x 3.0) (+ x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.1e-9) {
tmp = x + z;
} else if (z <= -1.75e-286) {
tmp = y * 2.0;
} else if (z <= 2.9e+23) {
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 <= (-6.1d-9)) then
tmp = x + z
else if (z <= (-1.75d-286)) then
tmp = y * 2.0d0
else if (z <= 2.9d+23) 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 <= -6.1e-9) {
tmp = x + z;
} else if (z <= -1.75e-286) {
tmp = y * 2.0;
} else if (z <= 2.9e+23) {
tmp = x * 3.0;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.1e-9: tmp = x + z elif z <= -1.75e-286: tmp = y * 2.0 elif z <= 2.9e+23: tmp = x * 3.0 else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.1e-9) tmp = Float64(x + z); elseif (z <= -1.75e-286) tmp = Float64(y * 2.0); elseif (z <= 2.9e+23) 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 <= -6.1e-9) tmp = x + z; elseif (z <= -1.75e-286) tmp = y * 2.0; elseif (z <= 2.9e+23) tmp = x * 3.0; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.1e-9], N[(x + z), $MachinePrecision], If[LessEqual[z, -1.75e-286], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, 2.9e+23], N[(x * 3.0), $MachinePrecision], N[(x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.1 \cdot 10^{-9}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -1.75 \cdot 10^{-286}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+23}:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -6.1e-9 or 2.90000000000000013e23 < z Initial program 99.9%
Taylor expanded in z around inf
Simplified63.3%
if -6.1e-9 < z < -1.74999999999999994e-286Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6467.3
Simplified67.3%
if -1.74999999999999994e-286 < z < 2.90000000000000013e23Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6457.8
Simplified57.8%
Final simplification62.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.8e+33) (fma 2.0 y z) (if (<= z 1.6e+50) (fma 2.0 (+ x y) x) (fma x 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.8e+33) {
tmp = fma(2.0, y, z);
} else if (z <= 1.6e+50) {
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 <= -2.8e+33) tmp = fma(2.0, y, z); elseif (z <= 1.6e+50) 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, -2.8e+33], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[z, 1.6e+50], 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 -2.8 \cdot 10^{+33}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+50}:\\
\;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\end{array}
\end{array}
if z < -2.8000000000000001e33Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6485.7
Simplified85.7%
if -2.8000000000000001e33 < z < 1.59999999999999991e50Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6490.7
Simplified90.7%
if 1.59999999999999991e50 < 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.5
Simplified84.5%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+137) (fma 2.0 y z) (if (<= y 3.2e+53) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+137) {
tmp = fma(2.0, y, z);
} else if (y <= 3.2e+53) {
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 <= -2.5e+137) tmp = fma(2.0, y, z); elseif (y <= 3.2e+53) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+137], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 3.2e+53], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+137}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+53}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -2.5000000000000001e137 or 3.2e53 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6485.6
Simplified85.6%
if -2.5000000000000001e137 < y < 3.2e53Initial 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.5
Simplified89.5%
(FPCore (x y z) :precision binary64 (if (<= x -5.6e+182) (* x 3.0) (if (<= x 9.5e+161) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.6e+182) {
tmp = x * 3.0;
} else if (x <= 9.5e+161) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.6e+182) tmp = Float64(x * 3.0); elseif (x <= 9.5e+161) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.6e+182], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 9.5e+161], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{+182}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+161}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -5.60000000000000013e182 or 9.50000000000000061e161 < x Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6475.2
Simplified75.2%
if -5.60000000000000013e182 < x < 9.50000000000000061e161Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6481.6
Simplified81.6%
(FPCore (x y z) :precision binary64 (if (<= y -2.85e+137) (* y 2.0) (if (<= y 3.35e+53) (+ x z) (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.85e+137) {
tmp = y * 2.0;
} else if (y <= 3.35e+53) {
tmp = x + z;
} else {
tmp = y * 2.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 (y <= (-2.85d+137)) then
tmp = y * 2.0d0
else if (y <= 3.35d+53) then
tmp = x + z
else
tmp = y * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.85e+137) {
tmp = y * 2.0;
} else if (y <= 3.35e+53) {
tmp = x + z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.85e+137: tmp = y * 2.0 elif y <= 3.35e+53: tmp = x + z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.85e+137) tmp = Float64(y * 2.0); elseif (y <= 3.35e+53) tmp = Float64(x + z); else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.85e+137) tmp = y * 2.0; elseif (y <= 3.35e+53) tmp = x + z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.85e+137], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 3.35e+53], N[(x + z), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.85 \cdot 10^{+137}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+53}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -2.8499999999999999e137 or 3.3499999999999999e53 < y Initial program 99.9%
Taylor expanded in y around inf
*-lowering-*.f6466.9
Simplified66.9%
if -2.8499999999999999e137 < y < 3.3499999999999999e53Initial program 99.9%
Taylor expanded in z around inf
Simplified53.1%
Final simplification58.6%
(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
Simplified39.5%
Final simplification39.5%
(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
Simplified34.7%
(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
Simplified39.5%
Taylor expanded in z around 0
Simplified7.5%
herbie shell --seed 2024205
(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))