
(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 6 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 (+ t (* y (+ (* x y) z))))
double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
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 * ((x * y) + z))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * ((x * y) + z));
}
def code(x, y, z, t): return t + (y * ((x * y) + z))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(Float64(x * y) + z))) end
function tmp = code(x, y, z, t) tmp = t + (y * ((x * y) + z)); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(x \cdot y + z\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -1.42e-11)
t_1
(if (<= y -1.3e-68)
t
(if (<= y -1.55e-110) (* y z) (if (<= y 2.9e-24) t t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.42e-11) {
tmp = t_1;
} else if (y <= -1.3e-68) {
tmp = t;
} else if (y <= -1.55e-110) {
tmp = y * z;
} else if (y <= 2.9e-24) {
tmp = t;
} 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 <= (-1.42d-11)) then
tmp = t_1
else if (y <= (-1.3d-68)) then
tmp = t
else if (y <= (-1.55d-110)) then
tmp = y * z
else if (y <= 2.9d-24) then
tmp = t
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 <= -1.42e-11) {
tmp = t_1;
} else if (y <= -1.3e-68) {
tmp = t;
} else if (y <= -1.55e-110) {
tmp = y * z;
} else if (y <= 2.9e-24) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -1.42e-11: tmp = t_1 elif y <= -1.3e-68: tmp = t elif y <= -1.55e-110: tmp = y * z elif y <= 2.9e-24: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -1.42e-11) tmp = t_1; elseif (y <= -1.3e-68) tmp = t; elseif (y <= -1.55e-110) tmp = Float64(y * z); elseif (y <= 2.9e-24) tmp = t; 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 <= -1.42e-11) tmp = t_1; elseif (y <= -1.3e-68) tmp = t; elseif (y <= -1.55e-110) tmp = y * z; elseif (y <= 2.9e-24) tmp = t; 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, -1.42e-11], t$95$1, If[LessEqual[y, -1.3e-68], t, If[LessEqual[y, -1.55e-110], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.9e-24], t, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.42 \cdot 10^{-11}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{-68}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-110}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-24}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.42e-11 or 2.8999999999999999e-24 < y Initial program 100.0%
Taylor expanded in t around 0 91.0%
Taylor expanded in z around 0 67.2%
if -1.42e-11 < y < -1.2999999999999999e-68 or -1.55000000000000004e-110 < y < 2.8999999999999999e-24Initial program 100.0%
Taylor expanded in y around 0 77.0%
if -1.2999999999999999e-68 < y < -1.55000000000000004e-110Initial program 100.0%
Taylor expanded in t around 0 91.4%
Taylor expanded in z around inf 67.2%
Final simplification71.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.3e-11) (not (<= y 7.8e-30))) (* y (+ (* x y) z)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.3e-11) || !(y <= 7.8e-30)) {
tmp = y * ((x * y) + z);
} 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.3d-11)) .or. (.not. (y <= 7.8d-30))) then
tmp = y * ((x * y) + z)
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.3e-11) || !(y <= 7.8e-30)) {
tmp = y * ((x * y) + z);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.3e-11) or not (y <= 7.8e-30): tmp = y * ((x * y) + z) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.3e-11) || !(y <= 7.8e-30)) tmp = Float64(y * Float64(Float64(x * y) + z)); 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.3e-11) || ~((y <= 7.8e-30))) tmp = y * ((x * y) + z); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.3e-11], N[Not[LessEqual[y, 7.8e-30]], $MachinePrecision]], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-11} \lor \neg \left(y \leq 7.8 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.30000000000000014e-11 or 7.8000000000000007e-30 < y Initial program 100.0%
Taylor expanded in t around 0 91.0%
if -2.30000000000000014e-11 < y < 7.8000000000000007e-30Initial program 100.0%
Taylor expanded in x around 0 92.4%
Final simplification91.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.05e+126) (not (<= y 2.1e+131))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.05e+126) || !(y <= 2.1e+131)) {
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.05d+126)) .or. (.not. (y <= 2.1d+131))) 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.05e+126) || !(y <= 2.1e+131)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.05e+126) or not (y <= 2.1e+131): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.05e+126) || !(y <= 2.1e+131)) 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.05e+126) || ~((y <= 2.1e+131))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.05e+126], N[Not[LessEqual[y, 2.1e+131]], $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.05 \cdot 10^{+126} \lor \neg \left(y \leq 2.1 \cdot 10^{+131}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.05e126 or 2.09999999999999985e131 < y Initial program 100.0%
Taylor expanded in t around 0 100.0%
Taylor expanded in z around 0 88.5%
if -1.05e126 < y < 2.09999999999999985e131Initial program 100.0%
Taylor expanded in x around 0 80.8%
Final simplification82.9%
(FPCore (x y z t) :precision binary64 (if (<= t -3.8e-16) t (if (<= t 5.2e-42) (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3.8e-16) {
tmp = t;
} else if (t <= 5.2e-42) {
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 (t <= (-3.8d-16)) then
tmp = t
else if (t <= 5.2d-42) 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 (t <= -3.8e-16) {
tmp = t;
} else if (t <= 5.2e-42) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3.8e-16: tmp = t elif t <= 5.2e-42: tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3.8e-16) tmp = t; elseif (t <= 5.2e-42) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -3.8e-16) tmp = t; elseif (t <= 5.2e-42) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3.8e-16], t, If[LessEqual[t, 5.2e-42], N[(y * z), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.8 \cdot 10^{-16}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 5.2 \cdot 10^{-42}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -3.80000000000000012e-16 or 5.2e-42 < t Initial program 100.0%
Taylor expanded in y around 0 59.0%
if -3.80000000000000012e-16 < t < 5.2e-42Initial program 99.9%
Taylor expanded in t around 0 85.8%
Taylor expanded in z around inf 46.3%
Final simplification53.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 100.0%
Taylor expanded in y around 0 40.3%
Final simplification40.3%
herbie shell --seed 2024039
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))