
(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 8 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-def100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -1.4e+80)
t_1
(if (<= y -1.4e-93)
(* y z)
(if (<= y 6.5e-24)
t
(if (or (<= y 0.028) (not (<= y 1.16e+45))) t_1 t))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.4e+80) {
tmp = t_1;
} else if (y <= -1.4e-93) {
tmp = y * z;
} else if (y <= 6.5e-24) {
tmp = t;
} else if ((y <= 0.028) || !(y <= 1.16e+45)) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_1 = y * (x * y)
if (y <= (-1.4d+80)) then
tmp = t_1
else if (y <= (-1.4d-93)) then
tmp = y * z
else if (y <= 6.5d-24) then
tmp = t
else if ((y <= 0.028d0) .or. (.not. (y <= 1.16d+45))) then
tmp = t_1
else
tmp = t
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 <= -1.4e+80) {
tmp = t_1;
} else if (y <= -1.4e-93) {
tmp = y * z;
} else if (y <= 6.5e-24) {
tmp = t;
} else if ((y <= 0.028) || !(y <= 1.16e+45)) {
tmp = t_1;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -1.4e+80: tmp = t_1 elif y <= -1.4e-93: tmp = y * z elif y <= 6.5e-24: tmp = t elif (y <= 0.028) or not (y <= 1.16e+45): tmp = t_1 else: tmp = t return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -1.4e+80) tmp = t_1; elseif (y <= -1.4e-93) tmp = Float64(y * z); elseif (y <= 6.5e-24) tmp = t; elseif ((y <= 0.028) || !(y <= 1.16e+45)) tmp = t_1; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); tmp = 0.0; if (y <= -1.4e+80) tmp = t_1; elseif (y <= -1.4e-93) tmp = y * z; elseif (y <= 6.5e-24) tmp = t; elseif ((y <= 0.028) || ~((y <= 1.16e+45))) tmp = t_1; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.4e+80], t$95$1, If[LessEqual[y, -1.4e-93], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.5e-24], t, If[Or[LessEqual[y, 0.028], N[Not[LessEqual[y, 1.16e+45]], $MachinePrecision]], t$95$1, t]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{+80}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-93}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-24}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 0.028 \lor \neg \left(y \leq 1.16 \cdot 10^{+45}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.39999999999999992e80 or 6.5e-24 < y < 0.0280000000000000006 or 1.1600000000000001e45 < y Initial program 100.0%
Taylor expanded in x around inf 76.3%
Taylor expanded in y around inf 73.8%
unpow273.8%
associate-*r*71.5%
Simplified71.5%
if -1.39999999999999992e80 < y < -1.39999999999999999e-93Initial program 99.8%
Taylor expanded in x around 0 76.0%
Taylor expanded in z around inf 48.4%
if -1.39999999999999999e-93 < y < 6.5e-24 or 0.0280000000000000006 < y < 1.1600000000000001e45Initial program 99.9%
Taylor expanded in y around 0 69.2%
Final simplification67.6%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -8e-52)
(not (or (<= y 1.15e-24) (and (not (<= y 0.0225)) (<= y 4e+44)))))
(* y (+ z (* x y)))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -8e-52) || !((y <= 1.15e-24) || (!(y <= 0.0225) && (y <= 4e+44)))) {
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 <= (-8d-52)) .or. (.not. (y <= 1.15d-24) .or. (.not. (y <= 0.0225d0)) .and. (y <= 4d+44))) 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 <= -8e-52) || !((y <= 1.15e-24) || (!(y <= 0.0225) && (y <= 4e+44)))) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -8e-52) or not ((y <= 1.15e-24) or (not (y <= 0.0225) and (y <= 4e+44))): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -8e-52) || !((y <= 1.15e-24) || (!(y <= 0.0225) && (y <= 4e+44)))) 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 <= -8e-52) || ~(((y <= 1.15e-24) || (~((y <= 0.0225)) && (y <= 4e+44))))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -8e-52], N[Not[Or[LessEqual[y, 1.15e-24], And[N[Not[LessEqual[y, 0.0225]], $MachinePrecision], LessEqual[y, 4e+44]]]], $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 -8 \cdot 10^{-52} \lor \neg \left(y \leq 1.15 \cdot 10^{-24} \lor \neg \left(y \leq 0.0225\right) \land y \leq 4 \cdot 10^{+44}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -8.0000000000000001e-52 or 1.1500000000000001e-24 < y < 0.022499999999999999 or 4.0000000000000004e44 < y Initial program 99.9%
Taylor expanded in t around 0 91.5%
if -8.0000000000000001e-52 < y < 1.1500000000000001e-24 or 0.022499999999999999 < y < 4.0000000000000004e44Initial program 99.9%
Taylor expanded in x around 0 93.7%
Final simplification92.5%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -7.5e+121)
(not (or (<= y 8.5e-24) (and (not (<= y 5.5e-5)) (<= y 3.4e+45)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.5e+121) || !((y <= 8.5e-24) || (!(y <= 5.5e-5) && (y <= 3.4e+45)))) {
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 <= (-7.5d+121)) .or. (.not. (y <= 8.5d-24) .or. (.not. (y <= 5.5d-5)) .and. (y <= 3.4d+45))) 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 <= -7.5e+121) || !((y <= 8.5e-24) || (!(y <= 5.5e-5) && (y <= 3.4e+45)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.5e+121) or not ((y <= 8.5e-24) or (not (y <= 5.5e-5) and (y <= 3.4e+45))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.5e+121) || !((y <= 8.5e-24) || (!(y <= 5.5e-5) && (y <= 3.4e+45)))) 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 <= -7.5e+121) || ~(((y <= 8.5e-24) || (~((y <= 5.5e-5)) && (y <= 3.4e+45))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.5e+121], N[Not[Or[LessEqual[y, 8.5e-24], And[N[Not[LessEqual[y, 5.5e-5]], $MachinePrecision], LessEqual[y, 3.4e+45]]]], $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 -7.5 \cdot 10^{+121} \lor \neg \left(y \leq 8.5 \cdot 10^{-24} \lor \neg \left(y \leq 5.5 \cdot 10^{-5}\right) \land y \leq 3.4 \cdot 10^{+45}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.49999999999999965e121 or 8.5000000000000002e-24 < y < 5.5000000000000002e-5 or 3.4e45 < y Initial program 100.0%
Taylor expanded in x around inf 77.6%
Taylor expanded in y around inf 76.7%
unpow276.7%
associate-*r*74.1%
Simplified74.1%
if -7.49999999999999965e121 < y < 8.5000000000000002e-24 or 5.5000000000000002e-5 < y < 3.4e45Initial program 99.9%
Taylor expanded in x around 0 88.2%
Final simplification82.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.4e+47) (not (<= z 4.5e+114))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.4e+47) || !(z <= 4.5e+114)) {
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 <= (-1.4d+47)) .or. (.not. (z <= 4.5d+114))) 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 <= -1.4e+47) || !(z <= 4.5e+114)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.4e+47) or not (z <= 4.5e+114): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.4e+47) || !(z <= 4.5e+114)) 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 <= -1.4e+47) || ~((z <= 4.5e+114))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.4e+47], N[Not[LessEqual[z, 4.5e+114]], $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 -1.4 \cdot 10^{+47} \lor \neg \left(z \leq 4.5 \cdot 10^{+114}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.39999999999999994e47 or 4.5000000000000001e114 < z Initial program 100.0%
Taylor expanded in x around 0 88.3%
if -1.39999999999999994e47 < z < 4.5000000000000001e114Initial program 99.9%
Taylor expanded in x around inf 91.9%
Final simplification90.5%
(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.46e+51) (* y z) (if (<= z 3.8e+59) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.46e+51) {
tmp = y * z;
} else if (z <= 3.8e+59) {
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.46d+51)) then
tmp = y * z
else if (z <= 3.8d+59) 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.46e+51) {
tmp = y * z;
} else if (z <= 3.8e+59) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.46e+51: tmp = y * z elif z <= 3.8e+59: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.46e+51) tmp = Float64(y * z); elseif (z <= 3.8e+59) 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.46e+51) tmp = y * z; elseif (z <= 3.8e+59) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.46e+51], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.8e+59], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.46 \cdot 10^{+51}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{+59}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.4600000000000001e51 or 3.8000000000000001e59 < z Initial program 100.0%
Taylor expanded in x around 0 84.8%
Taylor expanded in z around inf 64.4%
if -1.4600000000000001e51 < z < 3.8000000000000001e59Initial program 99.9%
Taylor expanded in y around 0 46.8%
Final simplification54.3%
(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 36.1%
Final simplification36.1%
herbie shell --seed 2023192
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))