
(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-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t) :precision binary64 (fma (+ z (* x y)) y t))
double code(double x, double y, double z, double t) {
return fma((z + (x * y)), y, t);
}
function code(x, y, z, t) return fma(Float64(z + Float64(x * y)), y, t) end
code[x_, y_, z_, t_] := N[(N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + x \cdot y, y, t\right)
\end{array}
Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -6800.0) t_1 (if (<= y 3e-14) t (if (<= y 1e+43) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -6800.0) {
tmp = t_1;
} else if (y <= 3e-14) {
tmp = t;
} else if (y <= 1e+43) {
tmp = y * z;
} 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 * (x * y)
if (y <= (-6800.0d0)) then
tmp = t_1
else if (y <= 3d-14) then
tmp = t
else if (y <= 1d+43) then
tmp = y * z
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 * (x * y);
double tmp;
if (y <= -6800.0) {
tmp = t_1;
} else if (y <= 3e-14) {
tmp = t;
} else if (y <= 1e+43) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -6800.0: tmp = t_1 elif y <= 3e-14: tmp = t elif y <= 1e+43: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -6800.0) tmp = t_1; elseif (y <= 3e-14) tmp = t; elseif (y <= 1e+43) tmp = Float64(y * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); tmp = 0.0; if (y <= -6800.0) tmp = t_1; elseif (y <= 3e-14) tmp = t; elseif (y <= 1e+43) tmp = y * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6800.0], t$95$1, If[LessEqual[y, 3e-14], t, If[LessEqual[y, 1e+43], N[(y * z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -6800:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-14}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 10^{+43}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6800 or 1.00000000000000001e43 < y Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in t around 0 89.2%
Taylor expanded in z around 0 71.7%
if -6800 < y < 2.9999999999999998e-14Initial program 99.9%
Taylor expanded in y around 0 63.1%
if 2.9999999999999998e-14 < y < 1.00000000000000001e43Initial program 99.9%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 65.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.8e+47) (not (<= z 4.6e+83))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+47) || !(z <= 4.6e+83)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
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 <= (-2.8d+47)) .or. (.not. (z <= 4.6d+83))) then
tmp = t + (y * z)
else
tmp = t + (y * (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+47) || !(z <= 4.6e+83)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.8e+47) or not (z <= 4.6e+83): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.8e+47) || !(z <= 4.6e+83)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(y * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.8e+47) || ~((z <= 4.6e+83))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.8e+47], N[Not[LessEqual[z, 4.6e+83]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+47} \lor \neg \left(z \leq 4.6 \cdot 10^{+83}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -2.79999999999999988e47 or 4.5999999999999999e83 < z Initial program 100.0%
Taylor expanded in x around 0 85.9%
if -2.79999999999999988e47 < z < 4.5999999999999999e83Initial program 99.9%
Taylor expanded in x around inf 93.8%
*-commutative93.8%
Simplified93.8%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -25500.0) (not (<= y 4.3e+24))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -25500.0) || !(y <= 4.3e+24)) {
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 <= (-25500.0d0)) .or. (.not. (y <= 4.3d+24))) 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 <= -25500.0) || !(y <= 4.3e+24)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -25500.0) or not (y <= 4.3e+24): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -25500.0) || !(y <= 4.3e+24)) 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 <= -25500.0) || ~((y <= 4.3e+24))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -25500.0], N[Not[LessEqual[y, 4.3e+24]], $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 -25500 \lor \neg \left(y \leq 4.3 \cdot 10^{+24}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -25500 or 4.29999999999999987e24 < y Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in t around 0 89.7%
if -25500 < y < 4.29999999999999987e24Initial program 99.9%
Taylor expanded in x around 0 86.8%
Final simplification88.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4e+65) (not (<= y 1.8e+144))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4e+65) || !(y <= 1.8e+144)) {
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 <= (-4d+65)) .or. (.not. (y <= 1.8d+144))) 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 <= -4e+65) || !(y <= 1.8e+144)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4e+65) or not (y <= 1.8e+144): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4e+65) || !(y <= 1.8e+144)) 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 <= -4e+65) || ~((y <= 1.8e+144))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4e+65], N[Not[LessEqual[y, 1.8e+144]], $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 -4 \cdot 10^{+65} \lor \neg \left(y \leq 1.8 \cdot 10^{+144}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4e65 or 1.7999999999999999e144 < y Initial program 99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in t around 0 97.8%
Taylor expanded in z around 0 80.8%
if -4e65 < y < 1.7999999999999999e144Initial program 99.9%
Taylor expanded in x around 0 80.4%
Final simplification80.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.2e+48) (not (<= z 2.1e+90))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.2e+48) || !(z <= 2.1e+90)) {
tmp = y * z;
} 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 ((z <= (-6.2d+48)) .or. (.not. (z <= 2.1d+90))) then
tmp = y * z
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.2e+48) || !(z <= 2.1e+90)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.2e+48) or not (z <= 2.1e+90): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.2e+48) || !(z <= 2.1e+90)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -6.2e+48) || ~((z <= 2.1e+90))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.2e+48], N[Not[LessEqual[z, 2.1e+90]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+48} \lor \neg \left(z \leq 2.1 \cdot 10^{+90}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -6.20000000000000011e48 or 2.09999999999999981e90 < z Initial program 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 68.1%
if -6.20000000000000011e48 < z < 2.09999999999999981e90Initial program 99.9%
Taylor expanded in y around 0 46.5%
Final simplification54.7%
(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 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 35.9%
herbie shell --seed 2024170
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))