
(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 7 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 (+ z (* y 2.0))))
double code(double x, double y, double z) {
return fma(x, 3.0, (z + (y * 2.0)));
}
function code(x, y, z) return fma(x, 3.0, Float64(z + Float64(y * 2.0))) end
code[x_, y_, z_] := N[(x * 3.0 + N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 3, z + y \cdot 2\right)
\end{array}
Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
associate-+r+N/A
+-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* y 2.0) (* x 3.0))))
(if (<= y -1e+153)
t_0
(if (<= y 2.4e+19)
(+ z (* x 3.0))
(if (<= y 2.35e+158) t_0 (+ z (* y 2.0)))))))
double code(double x, double y, double z) {
double t_0 = (y * 2.0) + (x * 3.0);
double tmp;
if (y <= -1e+153) {
tmp = t_0;
} else if (y <= 2.4e+19) {
tmp = z + (x * 3.0);
} else if (y <= 2.35e+158) {
tmp = t_0;
} else {
tmp = z + (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) :: t_0
real(8) :: tmp
t_0 = (y * 2.0d0) + (x * 3.0d0)
if (y <= (-1d+153)) then
tmp = t_0
else if (y <= 2.4d+19) then
tmp = z + (x * 3.0d0)
else if (y <= 2.35d+158) then
tmp = t_0
else
tmp = z + (y * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * 2.0) + (x * 3.0);
double tmp;
if (y <= -1e+153) {
tmp = t_0;
} else if (y <= 2.4e+19) {
tmp = z + (x * 3.0);
} else if (y <= 2.35e+158) {
tmp = t_0;
} else {
tmp = z + (y * 2.0);
}
return tmp;
}
def code(x, y, z): t_0 = (y * 2.0) + (x * 3.0) tmp = 0 if y <= -1e+153: tmp = t_0 elif y <= 2.4e+19: tmp = z + (x * 3.0) elif y <= 2.35e+158: tmp = t_0 else: tmp = z + (y * 2.0) return tmp
function code(x, y, z) t_0 = Float64(Float64(y * 2.0) + Float64(x * 3.0)) tmp = 0.0 if (y <= -1e+153) tmp = t_0; elseif (y <= 2.4e+19) tmp = Float64(z + Float64(x * 3.0)); elseif (y <= 2.35e+158) tmp = t_0; else tmp = Float64(z + Float64(y * 2.0)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * 2.0) + (x * 3.0); tmp = 0.0; if (y <= -1e+153) tmp = t_0; elseif (y <= 2.4e+19) tmp = z + (x * 3.0); elseif (y <= 2.35e+158) tmp = t_0; else tmp = z + (y * 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * 2.0), $MachinePrecision] + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e+153], t$95$0, If[LessEqual[y, 2.4e+19], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.35e+158], t$95$0, N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot 2 + x \cdot 3\\
\mathbf{if}\;y \leq -1 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+19}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot 2\\
\end{array}
\end{array}
if y < -1e153 or 2.4e19 < y < 2.35e158Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around 0
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6491.2%
Simplified91.2%
if -1e153 < y < 2.4e19Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6490.0%
Simplified90.0%
if 2.35e158 < y Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6494.8%
Simplified94.8%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* y 2.0)))) (if (<= y -3.9e+138) t_0 (if (<= y 4.2e-44) (+ z (* x 3.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (y * 2.0);
double tmp;
if (y <= -3.9e+138) {
tmp = t_0;
} else if (y <= 4.2e-44) {
tmp = z + (x * 3.0);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = z + (y * 2.0d0)
if (y <= (-3.9d+138)) then
tmp = t_0
else if (y <= 4.2d-44) then
tmp = z + (x * 3.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z + (y * 2.0);
double tmp;
if (y <= -3.9e+138) {
tmp = t_0;
} else if (y <= 4.2e-44) {
tmp = z + (x * 3.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z + (y * 2.0) tmp = 0 if y <= -3.9e+138: tmp = t_0 elif y <= 4.2e-44: tmp = z + (x * 3.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z + Float64(y * 2.0)) tmp = 0.0 if (y <= -3.9e+138) tmp = t_0; elseif (y <= 4.2e-44) tmp = Float64(z + Float64(x * 3.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z + (y * 2.0); tmp = 0.0; if (y <= -3.9e+138) tmp = t_0; elseif (y <= 4.2e-44) tmp = z + (x * 3.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.9e+138], t$95$0, If[LessEqual[y, 4.2e-44], N[(z + N[(x * 3.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + y \cdot 2\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+138}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-44}:\\
\;\;\;\;z + x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.8999999999999998e138 or 4.20000000000000003e-44 < y Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6486.1%
Simplified86.1%
if -3.8999999999999998e138 < y < 4.20000000000000003e-44Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6491.4%
Simplified91.4%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+178) (* x 3.0) (if (<= x 7.1e+174) (+ z (* y 2.0)) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+178) {
tmp = x * 3.0;
} else if (x <= 7.1e+174) {
tmp = z + (y * 2.0);
} 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.1d+178)) then
tmp = x * 3.0d0
else if (x <= 7.1d+174) then
tmp = z + (y * 2.0d0)
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.1e+178) {
tmp = x * 3.0;
} else if (x <= 7.1e+174) {
tmp = z + (y * 2.0);
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e+178: tmp = x * 3.0 elif x <= 7.1e+174: tmp = z + (y * 2.0) else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+178) tmp = Float64(x * 3.0); elseif (x <= 7.1e+174) tmp = Float64(z + Float64(y * 2.0)); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e+178) tmp = x * 3.0; elseif (x <= 7.1e+174) tmp = z + (y * 2.0); else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+178], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 7.1e+174], N[(z + N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+178}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 7.1 \cdot 10^{+174}:\\
\;\;\;\;z + y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.09999999999999999e178 or 7.1000000000000003e174 < x Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f6479.6%
Simplified79.6%
if -1.09999999999999999e178 < x < 7.1000000000000003e174Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6484.4%
Simplified84.4%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (<= y -8.2e+152) (* y 2.0) (if (<= y 1.65e+20) z (* y 2.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.2e+152) {
tmp = y * 2.0;
} else if (y <= 1.65e+20) {
tmp = 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 <= (-8.2d+152)) then
tmp = y * 2.0d0
else if (y <= 1.65d+20) then
tmp = 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 <= -8.2e+152) {
tmp = y * 2.0;
} else if (y <= 1.65e+20) {
tmp = z;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.2e+152: tmp = y * 2.0 elif y <= 1.65e+20: tmp = z else: tmp = y * 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.2e+152) tmp = Float64(y * 2.0); elseif (y <= 1.65e+20) tmp = z; else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.2e+152) tmp = y * 2.0; elseif (y <= 1.65e+20) tmp = z; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.2e+152], N[(y * 2.0), $MachinePrecision], If[LessEqual[y, 1.65e+20], z, N[(y * 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+152}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+20}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -8.1999999999999996e152 or 1.65e20 < y Initial program 100.0%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f6474.5%
Simplified74.5%
if -8.1999999999999996e152 < y < 1.65e20Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval99.9%
Simplified99.9%
Taylor expanded in z around inf
Simplified53.0%
Final simplification60.9%
(FPCore (x y z) :precision binary64 (+ z (+ (* y 2.0) (* x 3.0))))
double code(double x, double y, double z) {
return z + ((y * 2.0) + (x * 3.0));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((y * 2.0d0) + (x * 3.0d0))
end function
public static double code(double x, double y, double z) {
return z + ((y * 2.0) + (x * 3.0));
}
def code(x, y, z): return z + ((y * 2.0) + (x * 3.0))
function code(x, y, z) return Float64(z + Float64(Float64(y * 2.0) + Float64(x * 3.0))) end
function tmp = code(x, y, z) tmp = z + ((y * 2.0) + (x * 3.0)); end
code[x_, y_, z_] := N[(z + N[(N[(y * 2.0), $MachinePrecision] + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(y \cdot 2 + x \cdot 3\right)
\end{array}
Initial program 99.9%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
(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%
associate-+l+N/A
+-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+r+N/A
associate-+r+N/A
+-commutativeN/A
+-lowering-+.f64N/A
count-2N/A
*-commutativeN/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf
Simplified38.2%
herbie shell --seed 2024160
(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))