
(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 (<= z -1.2e+161)
(+ (+ z y) y)
(if (or (<= z -1.75e+65) (not (<= z 2.2e-68)))
(fma 3.0 x z)
(fma 3.0 x (+ y y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e+161) {
tmp = (z + y) + y;
} else if ((z <= -1.75e+65) || !(z <= 2.2e-68)) {
tmp = fma(3.0, x, z);
} else {
tmp = fma(3.0, x, (y + y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.2e+161) tmp = Float64(Float64(z + y) + y); elseif ((z <= -1.75e+65) || !(z <= 2.2e-68)) tmp = fma(3.0, x, z); else tmp = fma(3.0, x, Float64(y + y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.2e+161], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision], If[Or[LessEqual[z, -1.75e+65], N[Not[LessEqual[z, 2.2e-68]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(3.0 * x + N[(y + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+161}:\\
\;\;\;\;\left(z + y\right) + y\\
\mathbf{elif}\;z \leq -1.75 \cdot 10^{+65} \lor \neg \left(z \leq 2.2 \cdot 10^{-68}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, y + y\right)\\
\end{array}
\end{array}
if z < -1.1999999999999999e161Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Applied rewrites99.9%
if -1.1999999999999999e161 < z < -1.75e65 or 2.20000000000000002e-68 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f6484.2
Applied rewrites84.2%
if -1.75e65 < z < 2.20000000000000002e-68Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f6495.7
Applied rewrites95.7%
Taylor expanded in x around 0
Applied rewrites95.9%
Applied rewrites95.9%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e+89) (not (<= y 0.0026))) (+ (+ (* 2.0 y) z) x) (fma 3.0 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e+89) || !(y <= 0.0026)) {
tmp = ((2.0 * y) + z) + x;
} else {
tmp = fma(3.0, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e+89) || !(y <= 0.0026)) tmp = Float64(Float64(Float64(2.0 * y) + z) + x); else tmp = fma(3.0, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e+89], N[Not[LessEqual[y, 0.0026]], $MachinePrecision]], N[(N[(N[(2.0 * y), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+89} \lor \neg \left(y \leq 0.0026\right):\\
\;\;\;\;\left(2 \cdot y + z\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\end{array}
\end{array}
if y < -4.4e89 or 0.0025999999999999999 < y Initial program 99.9%
Taylor expanded in x around 0
lower-*.f6487.0
Applied rewrites87.0%
if -4.4e89 < y < 0.0025999999999999999Initial 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.7
Applied rewrites91.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.75e+25) (not (<= x 5.2e+93))) (fma 3.0 x z) (+ (+ z y) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.75e+25) || !(x <= 5.2e+93)) {
tmp = fma(3.0, x, z);
} else {
tmp = (z + y) + y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.75e+25) || !(x <= 5.2e+93)) tmp = fma(3.0, x, z); else tmp = Float64(Float64(z + y) + y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.75e+25], N[Not[LessEqual[x, 5.2e+93]], $MachinePrecision]], N[(3.0 * x + z), $MachinePrecision], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{+25} \lor \neg \left(x \leq 5.2 \cdot 10^{+93}\right):\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) + y\\
\end{array}
\end{array}
if x < -1.75e25 or 5.19999999999999999e93 < 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.0
Applied rewrites87.0%
if -1.75e25 < x < 5.19999999999999999e93Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6490.5
Applied rewrites90.5%
Applied rewrites90.5%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e+189) (not (<= x 1.5e+115))) (* 3.0 x) (+ (+ z y) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e+189) || !(x <= 1.5e+115)) {
tmp = 3.0 * x;
} else {
tmp = (z + 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 ((x <= (-4.8d+189)) .or. (.not. (x <= 1.5d+115))) then
tmp = 3.0d0 * x
else
tmp = (z + y) + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e+189) || !(x <= 1.5e+115)) {
tmp = 3.0 * x;
} else {
tmp = (z + y) + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e+189) or not (x <= 1.5e+115): tmp = 3.0 * x else: tmp = (z + y) + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e+189) || !(x <= 1.5e+115)) tmp = Float64(3.0 * x); else tmp = Float64(Float64(z + y) + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e+189) || ~((x <= 1.5e+115))) tmp = 3.0 * x; else tmp = (z + y) + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e+189], N[Not[LessEqual[x, 1.5e+115]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(N[(z + y), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+189} \lor \neg \left(x \leq 1.5 \cdot 10^{+115}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) + y\\
\end{array}
\end{array}
if x < -4.8000000000000001e189 or 1.5e115 < x Initial program 99.6%
Taylor expanded in x around inf
lower-*.f6480.4
Applied rewrites80.4%
if -4.8000000000000001e189 < x < 1.5e115Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6483.3
Applied rewrites83.3%
Applied rewrites83.3%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.4e+89) (not (<= y 5000000000.0))) (+ y y) (* 3.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.4e+89) || !(y <= 5000000000.0)) {
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 ((y <= (-4.4d+89)) .or. (.not. (y <= 5000000000.0d0))) 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 ((y <= -4.4e+89) || !(y <= 5000000000.0)) {
tmp = y + y;
} else {
tmp = 3.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.4e+89) or not (y <= 5000000000.0): tmp = y + y else: tmp = 3.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.4e+89) || !(y <= 5000000000.0)) 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 ((y <= -4.4e+89) || ~((y <= 5000000000.0))) tmp = y + y; else tmp = 3.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.4e+89], N[Not[LessEqual[y, 5000000000.0]], $MachinePrecision]], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+89} \lor \neg \left(y \leq 5000000000\right):\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot x\\
\end{array}
\end{array}
if y < -4.4e89 or 5e9 < y 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-+.f6475.4
Applied rewrites75.4%
Taylor expanded in x around 0
Applied rewrites62.8%
Applied rewrites62.8%
if -4.4e89 < y < 5e9Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6448.2
Applied rewrites48.2%
Final simplification54.1%
(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-+.f6464.5
Applied rewrites64.5%
Taylor expanded in x around 0
Applied rewrites32.3%
Applied rewrites32.3%
herbie shell --seed 2024320
(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))