
(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 2.0 (+ y x) (+ z x)))
double code(double x, double y, double z) {
return fma(2.0, (y + x), (z + x));
}
function code(x, y, z) return fma(2.0, Float64(y + x), Float64(z + x)) end
code[x_, y_, z_] := N[(2.0 * N[(y + x), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, y + x, z + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
count-2N/A
+-commutativeN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
(if (<= x -4.4e+162)
(fma 3.0 x z)
(if (<= x -55.0)
(fma 3.0 x (+ y y))
(if (<= x 1.52e+140) (fma 2.0 y z) (fma 3.0 x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e+162) {
tmp = fma(3.0, x, z);
} else if (x <= -55.0) {
tmp = fma(3.0, x, (y + y));
} else if (x <= 1.52e+140) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.4e+162) tmp = fma(3.0, x, z); elseif (x <= -55.0) tmp = fma(3.0, x, Float64(y + y)); elseif (x <= 1.52e+140) tmp = fma(2.0, y, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.4e+162], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, -55.0], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.52e+140], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+162}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq -55:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{elif}\;x \leq 1.52 \cdot 10^{+140}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -4.4000000000000004e162 or 1.52e140 < x Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6494.1
Applied rewrites94.1%
if -4.4000000000000004e162 < x < -55Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6481.1
Applied rewrites81.1%
Applied rewrites81.1%
if -55 < x < 1.52e140Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.5
Applied rewrites89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.38e+134) (not (<= x 1.52e+140))) (fma 3.0 x z) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.38e+134) || !(x <= 1.52e+140)) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.38e+134) || !(x <= 1.52e+140)) tmp = fma(3.0, x, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.38e+134], N[Not[LessEqual[x, 1.52e+140]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.38 \cdot 10^{+134} \lor \neg \left(x \leq 1.52 \cdot 10^{+140}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.38e134 or 1.52e140 < x Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6494.4
Applied rewrites94.4%
if -1.38e134 < x < 1.52e140Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6484.6
Applied rewrites84.6%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e+134) (not (<= x 2.05e+140))) (* 3.0 x) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+134) || !(x <= 2.05e+140)) {
tmp = 3.0 * x;
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e+134) || !(x <= 2.05e+140)) tmp = Float64(3.0 * x); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e+134], N[Not[LessEqual[x, 2.05e+140]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+134} \lor \neg \left(x \leq 2.05 \cdot 10^{+140}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.49999999999999998e134 or 2.0499999999999999e140 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6479.6
Applied rewrites79.6%
if -1.49999999999999998e134 < x < 2.0499999999999999e140Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6484.6
Applied rewrites84.6%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.5e+134) (not (<= x 2.05e+140))) (* 3.0 x) (+ (+ z y) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+134) || !(x <= 2.05e+140)) {
tmp = 3.0 * x;
} else {
tmp = (z + y) + 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 ((x <= (-1.5d+134)) .or. (.not. (x <= 2.05d+140))) then
tmp = 3.0d0 * x
else
tmp = (z + y) + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.5e+134) || !(x <= 2.05e+140)) {
tmp = 3.0 * x;
} else {
tmp = (z + y) + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.5e+134) or not (x <= 2.05e+140): tmp = 3.0 * x else: tmp = (z + y) + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.5e+134) || !(x <= 2.05e+140)) tmp = Float64(3.0 * x); else tmp = Float64(Float64(z + y) + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.5e+134) || ~((x <= 2.05e+140))) tmp = 3.0 * x; else tmp = (z + y) + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.5e+134], N[Not[LessEqual[x, 2.05e+140]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+134} \lor \neg \left(x \leq 2.05 \cdot 10^{+140}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) + y\\
\end{array}
\end{array}
if x < -1.49999999999999998e134 or 2.0499999999999999e140 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6479.6
Applied rewrites79.6%
if -1.49999999999999998e134 < x < 2.0499999999999999e140Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6484.6
Applied rewrites84.6%
Applied rewrites84.6%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.38e+134) (not (<= x 1.52e+140))) (* 3.0 x) (+ y y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.38e+134) || !(x <= 1.52e+140)) {
tmp = 3.0 * x;
} else {
tmp = y + 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 ((x <= (-1.38d+134)) .or. (.not. (x <= 1.52d+140))) then
tmp = 3.0d0 * x
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.38e+134) || !(x <= 1.52e+140)) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.38e+134) or not (x <= 1.52e+140): tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.38e+134) || !(x <= 1.52e+140)) tmp = Float64(3.0 * x); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.38e+134) || ~((x <= 1.52e+140))) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.38e+134], N[Not[LessEqual[x, 1.52e+140]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.38 \cdot 10^{+134} \lor \neg \left(x \leq 1.52 \cdot 10^{+140}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -1.38e134 or 1.52e140 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6479.6
Applied rewrites79.6%
if -1.38e134 < x < 1.52e140Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6461.8
Applied rewrites61.8%
Taylor expanded in x around 0
Applied rewrites46.7%
Applied rewrites46.7%
Final simplification56.6%
(FPCore (x y z) :precision binary64 (+ y y))
double code(double x, double y, double z) {
return y + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + y
end function
public static double code(double x, double y, double z) {
return y + y;
}
def code(x, y, z): return y + y
function code(x, y, z) return Float64(y + y) end
function tmp = code(x, y, z) tmp = y + y; end
code[x_, y_, z_] := N[(y + y), $MachinePrecision]
\begin{array}{l}
\\
y + y
\end{array}
Initial program 99.9%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6468.9
Applied rewrites68.9%
Taylor expanded in x around 0
Applied rewrites34.8%
Applied rewrites34.8%
herbie shell --seed 2024337
(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))