
(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 8 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 (let* ((t_0 (+ (+ (+ z y) (+ x y)) x))) (if (<= z -5.4e-46) t_0 (if (<= z 1.05e+110) (fma 3.0 x (+ y y)) t_0))))
double code(double x, double y, double z) {
double t_0 = ((z + y) + (x + y)) + x;
double tmp;
if (z <= -5.4e-46) {
tmp = t_0;
} else if (z <= 1.05e+110) {
tmp = fma(3.0, x, (y + y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(Float64(z + y) + Float64(x + y)) + x) tmp = 0.0 if (z <= -5.4e-46) tmp = t_0; elseif (z <= 1.05e+110) tmp = fma(3.0, x, Float64(y + y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(z + y), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -5.4e-46], t$95$0, If[LessEqual[z, 1.05e+110], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(z + y\right) + \left(x + y\right)\right) + x\\
\mathbf{if}\;z \leq -5.4 \cdot 10^{-46}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+110}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.4e-46 or 1.05000000000000007e110 < z 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-+.f6488.4
Applied rewrites88.4%
if -5.4e-46 < z < 1.05000000000000007e110Initial program 99.8%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.2
Applied rewrites92.2%
Applied rewrites92.2%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 3.0 x (+ y y)))) (if (<= x -1.7e+149) t_0 (if (<= x 3.8e-21) (fma y 2.0 z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(3.0, x, (y + y));
double tmp;
if (x <= -1.7e+149) {
tmp = t_0;
} else if (x <= 3.8e-21) {
tmp = fma(y, 2.0, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(3.0, x, Float64(y + y)) tmp = 0.0 if (x <= -1.7e+149) tmp = t_0; elseif (x <= 3.8e-21) tmp = fma(y, 2.0, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.7e+149], t$95$0, If[LessEqual[x, 3.8e-21], N[(y * 2.0 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(3, x, y + y\right)\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.6999999999999999e149 or 3.7999999999999998e-21 < x Initial program 99.8%
Taylor expanded in z around 0
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.2
Applied rewrites85.2%
Applied rewrites85.2%
if -1.6999999999999999e149 < x < 3.7999999999999998e-21Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.5
Applied rewrites92.5%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+166) (fma 3.0 x z) (if (<= x 8e+19) (fma y 2.0 z) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+166) {
tmp = fma(3.0, x, z);
} else if (x <= 8e+19) {
tmp = fma(y, 2.0, z);
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+166) tmp = fma(3.0, x, z); elseif (x <= 8e+19) tmp = fma(y, 2.0, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+166], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 8e+19], N[(y * 2.0 + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 8 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -5.40000000000000023e166 or 8e19 < 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.f6484.6
Applied rewrites84.6%
if -5.40000000000000023e166 < x < 8e19Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.9
Applied rewrites90.9%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+166) (fma 3.0 x z) (if (<= x 8e+19) (+ (+ z y) y) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+166) {
tmp = fma(3.0, x, z);
} else if (x <= 8e+19) {
tmp = (z + y) + y;
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+166) tmp = fma(3.0, x, z); elseif (x <= 8e+19) tmp = Float64(Float64(z + y) + y); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+166], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 8e+19], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 8 \cdot 10^{+19}:\\
\;\;\;\;\left(z + y\right) + y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -5.40000000000000023e166 or 8e19 < 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.f6484.6
Applied rewrites84.6%
if -5.40000000000000023e166 < x < 8e19Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.9
Applied rewrites90.9%
Applied rewrites90.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= x -9.5e+166) (* 3.0 x) (if (<= x 9.6e+145) (+ (+ z y) y) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.5e+166) {
tmp = 3.0 * x;
} else if (x <= 9.6e+145) {
tmp = (z + 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 <= (-9.5d+166)) then
tmp = 3.0d0 * x
else if (x <= 9.6d+145) then
tmp = (z + 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 <= -9.5e+166) {
tmp = 3.0 * x;
} else if (x <= 9.6e+145) {
tmp = (z + y) + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.5e+166: tmp = 3.0 * x elif x <= 9.6e+145: tmp = (z + y) + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.5e+166) tmp = Float64(3.0 * x); elseif (x <= 9.6e+145) tmp = Float64(Float64(z + y) + y); else tmp = Float64(3.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.5e+166) tmp = 3.0 * x; elseif (x <= 9.6e+145) tmp = (z + y) + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.5e+166], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 9.6e+145], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+166}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+145}:\\
\;\;\;\;\left(z + y\right) + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -9.49999999999999984e166 or 9.59999999999999967e145 < x Initial program 99.7%
Taylor expanded in x around inf
lower-*.f6478.5
Applied rewrites78.5%
if -9.49999999999999984e166 < x < 9.59999999999999967e145Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6486.1
Applied rewrites86.1%
Applied rewrites86.1%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+166) (* 3.0 x) (if (<= x 8e+19) (+ y y) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+166) {
tmp = 3.0 * x;
} else if (x <= 8e+19) {
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 <= (-5.4d+166)) then
tmp = 3.0d0 * x
else if (x <= 8d+19) 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 <= -5.4e+166) {
tmp = 3.0 * x;
} else if (x <= 8e+19) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.4e+166: tmp = 3.0 * x elif x <= 8e+19: tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+166) tmp = Float64(3.0 * x); elseif (x <= 8e+19) 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 <= -5.4e+166) tmp = 3.0 * x; elseif (x <= 8e+19) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+166], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 8e+19], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+166}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 8 \cdot 10^{+19}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -5.40000000000000023e166 or 8e19 < x Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6469.0
Applied rewrites69.0%
if -5.40000000000000023e166 < x < 8e19Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6450.5
Applied rewrites50.5%
Applied rewrites50.5%
(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
*-commutativeN/A
lower-*.f6437.9
Applied rewrites37.9%
Applied rewrites37.9%
herbie shell --seed 2024243
(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))