
(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 (+ z (+ (* 2.0 y) (* 3.0 x))))
double code(double x, double y, double z) {
return z + ((2.0 * y) + (3.0 * 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 + ((2.0d0 * y) + (3.0d0 * x))
end function
public static double code(double x, double y, double z) {
return z + ((2.0 * y) + (3.0 * x));
}
def code(x, y, z): return z + ((2.0 * y) + (3.0 * x))
function code(x, y, z) return Float64(z + Float64(Float64(2.0 * y) + Float64(3.0 * x))) end
function tmp = code(x, y, z) tmp = z + ((2.0 * y) + (3.0 * x)); end
code[x_, y_, z_] := N[(z + N[(N[(2.0 * y), $MachinePrecision] + N[(3.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(2 \cdot y + 3 \cdot x\right)
\end{array}
Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= z -1.55e+60)
z
(if (<= z -1.36e-229)
(* 3.0 x)
(if (<= z -1.12e-303)
(* 2.0 y)
(if (<= z 3.6e-81)
(* 3.0 x)
(if (<= z 1.52e-61) (* 2.0 y) (if (<= z 1.45e+41) (* 3.0 x) z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e+60) {
tmp = z;
} else if (z <= -1.36e-229) {
tmp = 3.0 * x;
} else if (z <= -1.12e-303) {
tmp = 2.0 * y;
} else if (z <= 3.6e-81) {
tmp = 3.0 * x;
} else if (z <= 1.52e-61) {
tmp = 2.0 * y;
} else if (z <= 1.45e+41) {
tmp = 3.0 * x;
} else {
tmp = z;
}
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 (z <= (-1.55d+60)) then
tmp = z
else if (z <= (-1.36d-229)) then
tmp = 3.0d0 * x
else if (z <= (-1.12d-303)) then
tmp = 2.0d0 * y
else if (z <= 3.6d-81) then
tmp = 3.0d0 * x
else if (z <= 1.52d-61) then
tmp = 2.0d0 * y
else if (z <= 1.45d+41) then
tmp = 3.0d0 * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.55e+60) {
tmp = z;
} else if (z <= -1.36e-229) {
tmp = 3.0 * x;
} else if (z <= -1.12e-303) {
tmp = 2.0 * y;
} else if (z <= 3.6e-81) {
tmp = 3.0 * x;
} else if (z <= 1.52e-61) {
tmp = 2.0 * y;
} else if (z <= 1.45e+41) {
tmp = 3.0 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.55e+60: tmp = z elif z <= -1.36e-229: tmp = 3.0 * x elif z <= -1.12e-303: tmp = 2.0 * y elif z <= 3.6e-81: tmp = 3.0 * x elif z <= 1.52e-61: tmp = 2.0 * y elif z <= 1.45e+41: tmp = 3.0 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.55e+60) tmp = z; elseif (z <= -1.36e-229) tmp = Float64(3.0 * x); elseif (z <= -1.12e-303) tmp = Float64(2.0 * y); elseif (z <= 3.6e-81) tmp = Float64(3.0 * x); elseif (z <= 1.52e-61) tmp = Float64(2.0 * y); elseif (z <= 1.45e+41) tmp = Float64(3.0 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.55e+60) tmp = z; elseif (z <= -1.36e-229) tmp = 3.0 * x; elseif (z <= -1.12e-303) tmp = 2.0 * y; elseif (z <= 3.6e-81) tmp = 3.0 * x; elseif (z <= 1.52e-61) tmp = 2.0 * y; elseif (z <= 1.45e+41) tmp = 3.0 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.55e+60], z, If[LessEqual[z, -1.36e-229], N[(3.0 * x), $MachinePrecision], If[LessEqual[z, -1.12e-303], N[(2.0 * y), $MachinePrecision], If[LessEqual[z, 3.6e-81], N[(3.0 * x), $MachinePrecision], If[LessEqual[z, 1.52e-61], N[(2.0 * y), $MachinePrecision], If[LessEqual[z, 1.45e+41], N[(3.0 * x), $MachinePrecision], z]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+60}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1.36 \cdot 10^{-229}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;z \leq -1.12 \cdot 10^{-303}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-81}:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;z \leq 1.52 \cdot 10^{-61}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+41}:\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.55e60 or 1.44999999999999994e41 < z Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 79.9%
if -1.55e60 < z < -1.36e-229 or -1.1199999999999999e-303 < z < 3.5999999999999999e-81 or 1.52000000000000003e-61 < z < 1.44999999999999994e41Initial program 99.8%
associate-+l+99.8%
+-commutative99.8%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 54.1%
if -1.36e-229 < z < -1.1199999999999999e-303 or 3.5999999999999999e-81 < z < 1.52000000000000003e-61Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 66.1%
Final simplification64.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.15e+61) (not (<= z 9e+41))) (+ z (* 2.0 y)) (+ x (* 2.0 (+ y x)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.15e+61) || !(z <= 9e+41)) {
tmp = z + (2.0 * y);
} else {
tmp = x + (2.0 * (y + 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 ((z <= (-2.15d+61)) .or. (.not. (z <= 9d+41))) then
tmp = z + (2.0d0 * y)
else
tmp = x + (2.0d0 * (y + x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.15e+61) || !(z <= 9e+41)) {
tmp = z + (2.0 * y);
} else {
tmp = x + (2.0 * (y + x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.15e+61) or not (z <= 9e+41): tmp = z + (2.0 * y) else: tmp = x + (2.0 * (y + x)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.15e+61) || !(z <= 9e+41)) tmp = Float64(z + Float64(2.0 * y)); else tmp = Float64(x + Float64(2.0 * Float64(y + x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.15e+61) || ~((z <= 9e+41))) tmp = z + (2.0 * y); else tmp = x + (2.0 * (y + x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.15e+61], N[Not[LessEqual[z, 9e+41]], $MachinePrecision]], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+61} \lor \neg \left(z \leq 9 \cdot 10^{+41}\right):\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + 2 \cdot \left(y + x\right)\\
\end{array}
\end{array}
if z < -2.1500000000000001e61 or 9.0000000000000002e41 < z Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 91.9%
if -2.1500000000000001e61 < z < 9.0000000000000002e41Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around 0 91.2%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e+232) (not (<= x 5e+125))) (* 3.0 x) (+ z (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+232) || !(x <= 5e+125)) {
tmp = 3.0 * x;
} else {
tmp = z + (2.0 * 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 <= (-4d+232)) .or. (.not. (x <= 5d+125))) then
tmp = 3.0d0 * x
else
tmp = z + (2.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+232) || !(x <= 5e+125)) {
tmp = 3.0 * x;
} else {
tmp = z + (2.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e+232) or not (x <= 5e+125): tmp = 3.0 * x else: tmp = z + (2.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e+232) || !(x <= 5e+125)) tmp = Float64(3.0 * x); else tmp = Float64(z + Float64(2.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e+232) || ~((x <= 5e+125))) tmp = 3.0 * x; else tmp = z + (2.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e+232], N[Not[LessEqual[x, 5e+125]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+232} \lor \neg \left(x \leq 5 \cdot 10^{+125}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 2 \cdot y\\
\end{array}
\end{array}
if x < -4.00000000000000023e232 or 4.99999999999999962e125 < x Initial program 99.7%
associate-+l+99.7%
+-commutative99.7%
associate-+l+99.7%
+-commutative99.7%
count-299.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around inf 89.8%
if -4.00000000000000023e232 < x < 4.99999999999999962e125Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 81.3%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e+73) (not (<= y 3.1e+27))) (+ z (* 2.0 y)) (+ z (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+73) || !(y <= 3.1e+27)) {
tmp = z + (2.0 * y);
} else {
tmp = z + (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 <= (-1.9d+73)) .or. (.not. (y <= 3.1d+27))) then
tmp = z + (2.0d0 * y)
else
tmp = z + (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e+73) || !(y <= 3.1e+27)) {
tmp = z + (2.0 * y);
} else {
tmp = z + (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e+73) or not (y <= 3.1e+27): tmp = z + (2.0 * y) else: tmp = z + (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e+73) || !(y <= 3.1e+27)) tmp = Float64(z + Float64(2.0 * y)); else tmp = Float64(z + Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.9e+73) || ~((y <= 3.1e+27))) tmp = z + (2.0 * y); else tmp = z + (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e+73], N[Not[LessEqual[y, 3.1e+27]], $MachinePrecision]], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+73} \lor \neg \left(y \leq 3.1 \cdot 10^{+27}\right):\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + 3 \cdot x\\
\end{array}
\end{array}
if y < -1.90000000000000011e73 or 3.09999999999999996e27 < y Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 86.8%
if -1.90000000000000011e73 < y < 3.09999999999999996e27Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around 0 88.4%
+-commutative88.4%
associate-+l+88.4%
distribute-lft1-in88.4%
metadata-eval88.4%
Simplified88.4%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.55e+61) z (if (<= z 5.8e-25) (* 2.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.55e+61) {
tmp = z;
} else if (z <= 5.8e-25) {
tmp = 2.0 * y;
} else {
tmp = z;
}
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 (z <= (-2.55d+61)) then
tmp = z
else if (z <= 5.8d-25) then
tmp = 2.0d0 * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.55e+61) {
tmp = z;
} else if (z <= 5.8e-25) {
tmp = 2.0 * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.55e+61: tmp = z elif z <= 5.8e-25: tmp = 2.0 * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.55e+61) tmp = z; elseif (z <= 5.8e-25) tmp = Float64(2.0 * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.55e+61) tmp = z; elseif (z <= 5.8e-25) tmp = 2.0 * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.55e+61], z, If[LessEqual[z, 5.8e-25], N[(2.0 * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.55 \cdot 10^{+61}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{-25}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.55000000000000005e61 or 5.8000000000000001e-25 < z Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 73.9%
if -2.55000000000000005e61 < z < 5.8000000000000001e-25Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around inf 45.3%
Final simplification57.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 35.7%
Final simplification35.7%
herbie shell --seed 2024034
(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))