
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
(FPCore (x y z t) :precision binary64 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= y -1.75e-40)
t_1
(if (<= y 1.1e-90)
(+ t (* y z))
(if (<= y 4e+34) (+ t (* x (* y y))) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.75e-40) {
tmp = t_1;
} else if (y <= 1.1e-90) {
tmp = t + (y * z);
} else if (y <= 4e+34) {
tmp = t + (x * (y * y));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (z + (x * y))
if (y <= (-1.75d-40)) then
tmp = t_1
else if (y <= 1.1d-90) then
tmp = t + (y * z)
else if (y <= 4d+34) then
tmp = t + (x * (y * y))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -1.75e-40) {
tmp = t_1;
} else if (y <= 1.1e-90) {
tmp = t + (y * z);
} else if (y <= 4e+34) {
tmp = t + (x * (y * y));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -1.75e-40: tmp = t_1 elif y <= 1.1e-90: tmp = t + (y * z) elif y <= 4e+34: tmp = t + (x * (y * y)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -1.75e-40) tmp = t_1; elseif (y <= 1.1e-90) tmp = Float64(t + Float64(y * z)); elseif (y <= 4e+34) tmp = Float64(t + Float64(x * Float64(y * y))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -1.75e-40) tmp = t_1; elseif (y <= 1.1e-90) tmp = t + (y * z); elseif (y <= 4e+34) tmp = t + (x * (y * y)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.75e-40], t$95$1, If[LessEqual[y, 1.1e-90], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e+34], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -1.75 \cdot 10^{-40}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-90}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+34}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.7500000000000001e-40 or 3.99999999999999978e34 < y Initial program 99.9%
Taylor expanded in t around 0 92.1%
if -1.7500000000000001e-40 < y < 1.09999999999999993e-90Initial program 100.0%
Taylor expanded in x around 0 95.9%
if 1.09999999999999993e-90 < y < 3.99999999999999978e34Initial program 99.7%
add-cube-cbrt98.7%
pow398.7%
*-commutative98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in z around 0 81.8%
pow-base-181.8%
*-lft-identity81.8%
*-commutative81.8%
unpow281.8%
Simplified81.8%
Final simplification92.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= y -5e-41)
t_1
(if (<= y 3.8e-77)
(+ t (* y z))
(if (<= y 8.6e+36) (+ t (* y (* x y))) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -5e-41) {
tmp = t_1;
} else if (y <= 3.8e-77) {
tmp = t + (y * z);
} else if (y <= 8.6e+36) {
tmp = t + (y * (x * y));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (z + (x * y))
if (y <= (-5d-41)) then
tmp = t_1
else if (y <= 3.8d-77) then
tmp = t + (y * z)
else if (y <= 8.6d+36) then
tmp = t + (y * (x * y))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -5e-41) {
tmp = t_1;
} else if (y <= 3.8e-77) {
tmp = t + (y * z);
} else if (y <= 8.6e+36) {
tmp = t + (y * (x * y));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -5e-41: tmp = t_1 elif y <= 3.8e-77: tmp = t + (y * z) elif y <= 8.6e+36: tmp = t + (y * (x * y)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -5e-41) tmp = t_1; elseif (y <= 3.8e-77) tmp = Float64(t + Float64(y * z)); elseif (y <= 8.6e+36) tmp = Float64(t + Float64(y * Float64(x * y))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -5e-41) tmp = t_1; elseif (y <= 3.8e-77) tmp = t + (y * z); elseif (y <= 8.6e+36) tmp = t + (y * (x * y)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5e-41], t$95$1, If[LessEqual[y, 3.8e-77], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.6e+36], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -5 \cdot 10^{-41}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-77}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{+36}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -4.9999999999999996e-41 or 8.6000000000000001e36 < y Initial program 99.9%
Taylor expanded in t around 0 92.1%
if -4.9999999999999996e-41 < y < 3.7999999999999999e-77Initial program 100.0%
Taylor expanded in x around 0 95.1%
if 3.7999999999999999e-77 < y < 8.6000000000000001e36Initial program 99.7%
Taylor expanded in x around inf 83.7%
unpow283.7%
associate-*r*83.8%
Simplified83.8%
Final simplification92.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.4e-42) (not (<= y 5.6e-62))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e-42) || !(y <= 5.6e-62)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-2.4d-42)) .or. (.not. (y <= 5.6d-62))) then
tmp = y * (z + (x * y))
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e-42) || !(y <= 5.6e-62)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.4e-42) or not (y <= 5.6e-62): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.4e-42) || !(y <= 5.6e-62)) tmp = Float64(y * Float64(z + Float64(x * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.4e-42) || ~((y <= 5.6e-62))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.4e-42], N[Not[LessEqual[y, 5.6e-62]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-42} \lor \neg \left(y \leq 5.6 \cdot 10^{-62}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.40000000000000003e-42 or 5.60000000000000005e-62 < y Initial program 99.9%
Taylor expanded in t around 0 87.7%
if -2.40000000000000003e-42 < y < 5.60000000000000005e-62Initial program 100.0%
Taylor expanded in x around 0 95.2%
Final simplification91.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.3e-40) (not (<= y 4.2e-62))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.3e-40) || !(y <= 4.2e-62)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-1.3d-40)) .or. (.not. (y <= 4.2d-62))) then
tmp = y * (x * y)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.3e-40) || !(y <= 4.2e-62)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.3e-40) or not (y <= 4.2e-62): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.3e-40) || !(y <= 4.2e-62)) tmp = Float64(y * Float64(x * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.3e-40) || ~((y <= 4.2e-62))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.3e-40], N[Not[LessEqual[y, 4.2e-62]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-40} \lor \neg \left(y \leq 4.2 \cdot 10^{-62}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.3000000000000001e-40 or 4.1999999999999998e-62 < y Initial program 99.9%
Taylor expanded in t around 0 87.7%
Taylor expanded in y around inf 63.1%
unpow263.1%
associate-*r*65.0%
Simplified65.0%
if -1.3000000000000001e-40 < y < 4.1999999999999998e-62Initial program 100.0%
Taylor expanded in y around 0 68.3%
Final simplification66.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.8e-40) (not (<= y 1.25e+114))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.8e-40) || !(y <= 1.25e+114)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-1.8d-40)) .or. (.not. (y <= 1.25d+114))) then
tmp = y * (x * y)
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.8e-40) || !(y <= 1.25e+114)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.8e-40) or not (y <= 1.25e+114): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.8e-40) || !(y <= 1.25e+114)) tmp = Float64(y * Float64(x * y)); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.8e-40) || ~((y <= 1.25e+114))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.8e-40], N[Not[LessEqual[y, 1.25e+114]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-40} \lor \neg \left(y \leq 1.25 \cdot 10^{+114}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.8e-40 or 1.25e114 < y Initial program 99.9%
Taylor expanded in t around 0 93.7%
Taylor expanded in y around inf 68.8%
unpow268.8%
associate-*r*71.4%
Simplified71.4%
if -1.8e-40 < y < 1.25e114Initial program 99.9%
Taylor expanded in x around 0 85.9%
Final simplification80.0%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t + (y * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.05e+23) (* y z) (if (<= z 2.2e+81) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.05e+23) {
tmp = y * z;
} else if (z <= 2.2e+81) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.05d+23)) then
tmp = y * z
else if (z <= 2.2d+81) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.05e+23) {
tmp = y * z;
} else if (z <= 2.2e+81) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.05e+23: tmp = y * z elif z <= 2.2e+81: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.05e+23) tmp = Float64(y * z); elseif (z <= 2.2e+81) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.05e+23) tmp = y * z; elseif (z <= 2.2e+81) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.05e+23], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.2e+81], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+23}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+81}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.0500000000000001e23 or 2.19999999999999987e81 < z Initial program 100.0%
Taylor expanded in t around 0 76.5%
Taylor expanded in y around 0 62.1%
if -1.0500000000000001e23 < z < 2.19999999999999987e81Initial program 99.9%
Taylor expanded in y around 0 48.1%
Final simplification54.4%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 37.6%
Final simplification37.6%
herbie shell --seed 2023279
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))