
(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 (+ (+ z (+ (+ (+ y x) y) x)) x))
double code(double x, double y, double z) {
return (z + (((y + x) + y) + x)) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z + (((y + x) + y) + x)) + x
end function
public static double code(double x, double y, double z) {
return (z + (((y + x) + y) + x)) + x;
}
def code(x, y, z): return (z + (((y + x) + y) + x)) + x
function code(x, y, z) return Float64(Float64(z + Float64(Float64(Float64(y + x) + y) + x)) + x) end
function tmp = code(x, y, z) tmp = (z + (((y + x) + y) + x)) + x; end
code[x_, y_, z_] := N[(N[(z + N[(N[(N[(y + x), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(z + \left(\left(\left(y + x\right) + y\right) + x\right)\right) + x
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 3.0 x (+ y y)))) (if (<= x -9.5e+92) t_0 (if (<= x 1.06e-11) (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 <= -9.5e+92) {
tmp = t_0;
} else if (x <= 1.06e-11) {
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 <= -9.5e+92) tmp = t_0; elseif (x <= 1.06e-11) 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, -9.5e+92], t$95$0, If[LessEqual[x, 1.06e-11], 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 -9.5 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.06 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.4999999999999995e92 or 1.05999999999999993e-11 < 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
*-commutativeN/A
lower-*.f6486.0
Applied rewrites86.0%
Applied rewrites86.0%
if -9.4999999999999995e92 < x < 1.05999999999999993e-11Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6491.4
Applied rewrites91.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e+77) (fma 3.0 x z) (if (<= x 1.82e+111) (fma y 2.0 z) (fma 3.0 x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+77) {
tmp = fma(3.0, x, z);
} else if (x <= 1.82e+111) {
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 <= -1.9e+77) tmp = fma(3.0, x, z); elseif (x <= 1.82e+111) tmp = fma(y, 2.0, z); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+77], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 1.82e+111], N[(y * 2.0 + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+77}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{elif}\;x \leq 1.82 \cdot 10^{+111}:\\
\;\;\;\;\mathsf{fma}\left(y, 2, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if x < -1.9000000000000001e77 or 1.82000000000000006e111 < x Initial program 99.6%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6483.9
Applied rewrites83.9%
if -1.9000000000000001e77 < x < 1.82000000000000006e111Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6489.4
Applied rewrites89.4%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+149) (+ y y) (if (<= y 1.55e+89) (fma 3.0 x z) (+ y y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+149) {
tmp = y + y;
} else if (y <= 1.55e+89) {
tmp = fma(3.0, x, z);
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+149) tmp = Float64(y + y); elseif (y <= 1.55e+89) tmp = fma(3.0, x, z); else tmp = Float64(y + y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+149], N[(y + y), $MachinePrecision], If[LessEqual[y, 1.55e+89], N[(3.0 * x + z), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+149}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+89}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if y < -1.1e149 or 1.55e89 < y Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6480.8
Applied rewrites80.8%
Applied rewrites80.8%
if -1.1e149 < y < 1.55e89Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6480.1
Applied rewrites80.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e+77) (* 3.0 x) (if (<= x 1.82e+111) (+ y y) (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e+77) {
tmp = 3.0 * x;
} else if (x <= 1.82e+111) {
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.9d+77)) then
tmp = 3.0d0 * x
else if (x <= 1.82d+111) 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.9e+77) {
tmp = 3.0 * x;
} else if (x <= 1.82e+111) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e+77: tmp = 3.0 * x elif x <= 1.82e+111: tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e+77) tmp = Float64(3.0 * x); elseif (x <= 1.82e+111) 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.9e+77) tmp = 3.0 * x; elseif (x <= 1.82e+111) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e+77], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 1.82e+111], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+77}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;x \leq 1.82 \cdot 10^{+111}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if x < -1.9000000000000001e77 or 1.82000000000000006e111 < x Initial program 99.6%
Taylor expanded in x around inf
lower-*.f6468.4
Applied rewrites68.4%
if -1.9000000000000001e77 < x < 1.82000000000000006e111Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6452.3
Applied rewrites52.3%
Applied rewrites52.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
*-commutativeN/A
lower-*.f6441.4
Applied rewrites41.4%
Applied rewrites41.4%
herbie shell --seed 2024270
(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))