
(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 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%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -6.5e+80) (fma 3.0 x z) (if (<= x 6.6e+74) (+ (fma 2.0 y z) x) (fma 3.0 x (+ y y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e+80) {
tmp = fma(3.0, x, z);
} else if (x <= 6.6e+74) {
tmp = fma(2.0, y, z) + x;
} else {
tmp = fma(3.0, x, (y + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6.5e+80) tmp = fma(3.0, x, z); elseif (x <= 6.6e+74) tmp = Float64(fma(2.0, y, z) + x); else tmp = fma(3.0, x, Float64(y + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6.5e+80], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 6.6e+74], N[(N[(2.0 * y + z), $MachinePrecision] + x), $MachinePrecision], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{+74}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\end{array}
\end{array}
if x < -6.4999999999999998e80Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6495.2
Applied rewrites95.2%
if -6.4999999999999998e80 < x < 6.6000000000000004e74Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.9
Applied rewrites90.9%
if 6.6000000000000004e74 < x Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6485.7
Applied rewrites85.7%
Taylor expanded in x around 0
Applied rewrites85.8%
Applied rewrites85.8%
(FPCore (x y z) :precision binary64 (if (<= x -6.5e+80) (fma 3.0 x z) (if (<= x 4.8e+74) (fma 2.0 y z) (fma 3.0 x (+ y y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e+80) {
tmp = fma(3.0, x, z);
} else if (x <= 4.8e+74) {
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 <= -6.5e+80) tmp = fma(3.0, x, z); elseif (x <= 4.8e+74) 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, -6.5e+80], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 4.8e+74], 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 -6.5 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+74}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\end{array}
\end{array}
if x < -6.4999999999999998e80Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6495.2
Applied rewrites95.2%
if -6.4999999999999998e80 < x < 4.80000000000000017e74Initial program 100.0%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6489.4
Applied rewrites89.4%
if 4.80000000000000017e74 < x Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6485.7
Applied rewrites85.7%
Taylor expanded in x around 0
Applied rewrites85.8%
Applied rewrites85.8%
(FPCore (x y z) :precision binary64 (if (<= x -6.5e+80) (fma 3.0 x z) (if (<= x 4.9e+16) (fma 2.0 y z) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e+80) {
tmp = fma(3.0, x, z);
} else if (x <= 4.9e+16) {
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 <= -6.5e+80) tmp = fma(3.0, x, z); elseif (x <= 4.9e+16) tmp = fma(2.0, y, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6.5e+80], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 4.9e+16], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 4.9 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -6.4999999999999998e80 or 4.9e16 < 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.f6487.5
Applied rewrites87.5%
if -6.4999999999999998e80 < x < 4.9e16Initial program 100.0%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6491.1
Applied rewrites91.1%
(FPCore (x y z) :precision binary64 (if (<= x -3.8e+144) (* 3.0 x) (if (<= x 9.6e+88) (fma 2.0 y z) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e+144) {
tmp = 3.0 * x;
} else if (x <= 9.6e+88) {
tmp = fma(2.0, y, z);
} else {
tmp = 3.0 * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.8e+144) tmp = Float64(3.0 * x); elseif (x <= 9.6e+88) tmp = fma(2.0, y, z); else tmp = Float64(3.0 * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.8e+144], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 9.6e+88], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+144}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+88}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -3.80000000000000026e144 or 9.5999999999999996e88 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6477.3
Applied rewrites77.3%
if -3.80000000000000026e144 < x < 9.5999999999999996e88Initial program 100.0%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.5
Applied rewrites87.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.42e+73) (* 3.0 x) (if (<= x 4.4e-28) (+ y y) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.42e+73) {
tmp = 3.0 * x;
} else if (x <= 4.4e-28) {
tmp = y + y;
} 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 <= (-1.42d+73)) then
tmp = 3.0d0 * x
else if (x <= 4.4d-28) then
tmp = y + y
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 <= -1.42e+73) {
tmp = 3.0 * x;
} else if (x <= 4.4e-28) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.42e+73: tmp = 3.0 * x elif x <= 4.4e-28: tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.42e+73) tmp = Float64(3.0 * x); elseif (x <= 4.4e-28) tmp = Float64(y + y); else tmp = Float64(3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.42e+73) tmp = 3.0 * x; elseif (x <= 4.4e-28) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.42e+73], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 4.4e-28], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.42 \cdot 10^{+73}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-28}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -1.4199999999999999e73 or 4.39999999999999992e-28 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6464.8
Applied rewrites64.8%
if -1.4199999999999999e73 < x < 4.39999999999999992e-28Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6451.5
Applied rewrites51.5%
Taylor expanded in x around 0
Applied rewrites44.3%
Applied rewrites44.3%
(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
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6462.9
Applied rewrites62.9%
Taylor expanded in x around 0
Applied rewrites31.9%
Applied rewrites31.9%
herbie shell --seed 2024294
(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))