
(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 (+ (+ x (+ y (+ x y))) z)))
double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((x + (y + (x + y))) + z)
end function
public static double code(double x, double y, double z) {
return x + ((x + (y + (x + y))) + z);
}
def code(x, y, z): return x + ((x + (y + (x + y))) + z)
function code(x, y, z) return Float64(x + Float64(Float64(x + Float64(y + Float64(x + y))) + z)) end
function tmp = code(x, y, z) tmp = x + ((x + (y + (x + y))) + z); end
code[x_, y_, z_] := N[(x + N[(N[(x + N[(y + N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(x + \left(y + \left(x + y\right)\right)\right) + z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 2.0 (+ x y) x))) (if (<= x -8.5e+14) t_0 (if (<= x 1.06e-26) (fma 2.0 y z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(2.0, (x + y), x);
double tmp;
if (x <= -8.5e+14) {
tmp = t_0;
} else if (x <= 1.06e-26) {
tmp = fma(2.0, y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(2.0, Float64(x + y), x) tmp = 0.0 if (x <= -8.5e+14) tmp = t_0; elseif (x <= 1.06e-26) tmp = fma(2.0, y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(2.0 * N[(x + y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -8.5e+14], t$95$0, If[LessEqual[x, 1.06e-26], N[(2.0 * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(2, x + y, x\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.06 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.5e14 or 1.06000000000000001e-26 < x Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6488.0
Applied rewrites88.0%
if -8.5e14 < x < 1.06000000000000001e-26Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6495.2
Applied rewrites95.2%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.06e+114) (fma 2.0 y z) (if (<= y 42000000000000.0) (fma x 3.0 z) (fma 2.0 y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e+114) {
tmp = fma(2.0, y, z);
} else if (y <= 42000000000000.0) {
tmp = fma(x, 3.0, z);
} else {
tmp = fma(2.0, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.06e+114) tmp = fma(2.0, y, z); elseif (y <= 42000000000000.0) tmp = fma(x, 3.0, z); else tmp = fma(2.0, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.06e+114], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[y, 42000000000000.0], N[(x * 3.0 + z), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{elif}\;y \leq 42000000000000:\\
\;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\end{array}
\end{array}
if y < -1.05999999999999993e114 or 4.2e13 < y Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6484.6
Applied rewrites84.6%
if -1.05999999999999993e114 < y < 4.2e13Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6488.3
Applied rewrites88.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e+20) (* x 3.0) (if (<= x 1.45e+179) (fma 2.0 y z) (* x 3.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+20) {
tmp = x * 3.0;
} else if (x <= 1.45e+179) {
tmp = fma(2.0, y, z);
} else {
tmp = x * 3.0;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+20) tmp = Float64(x * 3.0); elseif (x <= 1.45e+179) tmp = fma(2.0, y, z); else tmp = Float64(x * 3.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+20], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.45e+179], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+20}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
if x < -1.1e20 or 1.45000000000000009e179 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6468.4
Applied rewrites68.4%
if -1.1e20 < x < 1.45000000000000009e179Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6486.2
Applied rewrites86.2%
(FPCore (x y z) :precision binary64 (if (<= y -520.0) (+ y y) (if (<= y 42000000000000.0) (* x 3.0) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -520.0) {
tmp = y + y;
} else if (y <= 42000000000000.0) {
tmp = x * 3.0;
} 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 <= (-520.0d0)) then
tmp = y + y
else if (y <= 42000000000000.0d0) then
tmp = x * 3.0d0
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -520.0) {
tmp = y + y;
} else if (y <= 42000000000000.0) {
tmp = x * 3.0;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -520.0: tmp = y + y elif y <= 42000000000000.0: tmp = x * 3.0 else: tmp = y + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -520.0) tmp = Float64(y + y); elseif (y <= 42000000000000.0) tmp = Float64(x * 3.0); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -520.0) tmp = y + y; elseif (y <= 42000000000000.0) tmp = x * 3.0; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -520.0], N[(y + y), $MachinePrecision], If[LessEqual[y, 42000000000000.0], N[(x * 3.0), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -520:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 42000000000000:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -520 or 4.2e13 < y Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6464.6
Applied rewrites64.6%
Applied rewrites64.6%
if -520 < y < 4.2e13Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6455.3
Applied rewrites55.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 y around inf
lower-*.f6442.7
Applied rewrites42.7%
Applied rewrites42.7%
herbie shell --seed 2024233
(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))