
(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 (+ x y) (+ z x)))
double code(double x, double y, double z) {
return fma(2.0, (x + y), (z + x));
}
function code(x, y, z) return fma(2.0, Float64(x + y), Float64(z + x)) end
code[x_, y_, z_] := N[(2.0 * N[(x + y), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, x + y, 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%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e+82) (fma 3.0 x (+ y y)) (if (<= y 1.8e+67) (fma 3.0 x z) (+ (+ (+ z y) (+ x y)) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e+82) {
tmp = fma(3.0, x, (y + y));
} else if (y <= 1.8e+67) {
tmp = fma(3.0, x, z);
} else {
tmp = ((z + y) + (x + y)) + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.4e+82) tmp = fma(3.0, x, Float64(y + y)); elseif (y <= 1.8e+67) tmp = fma(3.0, x, z); else tmp = Float64(Float64(Float64(z + y) + Float64(x + y)) + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.4e+82], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.8e+67], N[(3.0 * x + z), $MachinePrecision], N[(N[(N[(z + y), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(z + y\right) + \left(x + y\right)\right) + x\\
\end{array}
\end{array}
if y < -1.4e82Initial 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-*.f6484.7
Applied rewrites84.7%
Applied rewrites84.7%
if -1.4e82 < y < 1.7999999999999999e67Initial 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.8
Applied rewrites91.8%
if 1.7999999999999999e67 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f6492.3
Applied rewrites92.3%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.4e+82) (fma 3.0 x (+ y y)) (if (<= y 1.8e+67) (fma 3.0 x z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.4e+82) {
tmp = fma(3.0, x, (y + y));
} else if (y <= 1.8e+67) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.4e+82) tmp = fma(3.0, x, Float64(y + y)); elseif (y <= 1.8e+67) tmp = fma(3.0, x, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.4e+82], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.8e+67], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -1.4e82Initial 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-*.f6484.7
Applied rewrites84.7%
Applied rewrites84.7%
if -1.4e82 < y < 1.7999999999999999e67Initial 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.8
Applied rewrites91.8%
if 1.7999999999999999e67 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.9
Applied rewrites90.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e+155) (fma 2.0 y z) (if (<= y 1.8e+67) (fma 3.0 x z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e+155) {
tmp = fma(2.0, y, z);
} else if (y <= 1.8e+67) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.9e+155) tmp = fma(2.0, y, z); elseif (y <= 1.8e+67) tmp = fma(3.0, x, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.9e+155], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 1.8e+67], N[(3.0 * x + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+155}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -2.8999999999999999e155 or 1.7999999999999999e67 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.5
Applied rewrites90.5%
if -2.8999999999999999e155 < y < 1.7999999999999999e67Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6489.2
Applied rewrites89.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e+154) (* 3.0 x) (if (<= x 3.9e+235) (fma 2.0 y z) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+154) {
tmp = 3.0 * x;
} else if (x <= 3.9e+235) {
tmp = fma(2.0, y, z);
} else {
tmp = 3.0 * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+154) tmp = Float64(3.0 * x); elseif (x <= 3.9e+235) tmp = fma(2.0, y, z); else tmp = Float64(3.0 * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+154], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 3.9e+235], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+154}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+235}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -1.6e154 or 3.9000000000000003e235 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6480.0
Applied rewrites80.0%
if -1.6e154 < x < 3.9000000000000003e235Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6482.2
Applied rewrites82.2%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e+155) (+ y y) (if (<= y 1.8e+67) (* 3.0 x) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e+155) {
tmp = y + y;
} else if (y <= 1.8e+67) {
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 (y <= (-2.9d+155)) then
tmp = y + y
else if (y <= 1.8d+67) 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 (y <= -2.9e+155) {
tmp = y + y;
} else if (y <= 1.8e+67) {
tmp = 3.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.9e+155: tmp = y + y elif y <= 1.8e+67: tmp = 3.0 * x else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.9e+155) tmp = Float64(y + y); elseif (y <= 1.8e+67) 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 (y <= -2.9e+155) tmp = y + y; elseif (y <= 1.8e+67) tmp = 3.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.9e+155], N[(y + y), $MachinePrecision], If[LessEqual[y, 1.8e+67], N[(3.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+155}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -2.8999999999999999e155 or 1.7999999999999999e67 < y Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6475.8
Applied rewrites75.8%
Applied rewrites75.8%
if -2.8999999999999999e155 < y < 1.7999999999999999e67Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6442.9
Applied rewrites42.9%
(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 y around inf
lower-*.f6432.8
Applied rewrites32.8%
Applied rewrites32.8%
herbie shell --seed 2024276
(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))