
(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 6 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 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}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.4e+72) (fma 3.0 x z) (if (<= x 1.76e+46) (fma 2.0 y z) (fma 3.0 x (+ y y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.4e+72) {
tmp = fma(3.0, x, z);
} else if (x <= 1.76e+46) {
tmp = fma(2.0, y, z);
} else {
tmp = fma(3.0, x, (y + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.4e+72) tmp = fma(3.0, x, z); elseif (x <= 1.76e+46) tmp = fma(2.0, y, z); else tmp = fma(3.0, x, Float64(y + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.4e+72], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 1.76e+46], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+72}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 1.76 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\end{array}
\end{array}
if x < -1.4e72Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6494.8
Applied rewrites94.8%
if -1.4e72 < x < 1.76e46Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.7
Applied rewrites90.7%
if 1.76e46 < x Initial program 99.7%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
Applied rewrites93.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e+72) (not (<= x 9.5e+81))) (fma 3.0 x z) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e+72) || !(x <= 9.5e+81)) {
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.4e+72) || !(x <= 9.5e+81)) 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.4e+72], N[Not[LessEqual[x, 9.5e+81]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+72} \lor \neg \left(x \leq 9.5 \cdot 10^{+81}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.4e72 or 9.50000000000000083e81 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6491.3
Applied rewrites91.3%
if -1.4e72 < x < 9.50000000000000083e81Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.1
Applied rewrites90.1%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.22e+76) (not (<= x 1.6e+90))) (* 3.0 x) (fma 2.0 y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.22e+76) || !(x <= 1.6e+90)) {
tmp = 3.0 * x;
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.22e+76) || !(x <= 1.6e+90)) 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.22e+76], N[Not[LessEqual[x, 1.6e+90]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{+76} \lor \neg \left(x \leq 1.6 \cdot 10^{+90}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if x < -1.22000000000000002e76 or 1.59999999999999999e90 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6483.0
Applied rewrites83.0%
if -1.22000000000000002e76 < x < 1.59999999999999999e90Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.7
Applied rewrites89.7%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e+72) (not (<= x 9.5e+81))) (* 3.0 x) (+ y y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e+72) || !(x <= 9.5e+81)) {
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.4d+72)) .or. (.not. (x <= 9.5d+81))) 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.4e+72) || !(x <= 9.5e+81)) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e+72) or not (x <= 9.5e+81): tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e+72) || !(x <= 9.5e+81)) 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.4e+72) || ~((x <= 9.5e+81))) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e+72], N[Not[LessEqual[x, 9.5e+81]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+72} \lor \neg \left(x \leq 9.5 \cdot 10^{+81}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -1.4e72 or 9.50000000000000083e81 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6482.1
Applied rewrites82.1%
if -1.4e72 < x < 9.50000000000000083e81Initial program 100.0%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6458.4
Applied rewrites58.4%
Taylor expanded in x around 0
Applied rewrites48.8%
Applied rewrites48.8%
Final simplification59.0%
(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.3
Applied rewrites68.3%
Taylor expanded in x around 0
Applied rewrites36.9%
Applied rewrites36.9%
herbie shell --seed 2024318
(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))