
(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 y (fma x y z) t))
double code(double x, double y, double z, double t) {
return fma(y, fma(x, y, z), t);
}
function code(x, y, z, t) return fma(y, fma(x, y, z), t) end
code[x_, y_, z_, t_] := N[(y * N[(x * y + z), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \mathsf{fma}\left(x, y, z\right), t\right)
\end{array}
Initial program 99.9%
*-commutative99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t)
:precision binary64
(if (<= y -9.2e+105)
(* y (* y x))
(if (or (<= y -0.0011) (and (not (<= y -4e-25)) (<= y 1.52e+85)))
(+ t (* y z))
(* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -9.2e+105) {
tmp = y * (y * x);
} else if ((y <= -0.0011) || (!(y <= -4e-25) && (y <= 1.52e+85))) {
tmp = t + (y * z);
} else {
tmp = x * (y * 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 (y <= (-9.2d+105)) then
tmp = y * (y * x)
else if ((y <= (-0.0011d0)) .or. (.not. (y <= (-4d-25))) .and. (y <= 1.52d+85)) then
tmp = t + (y * z)
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -9.2e+105) {
tmp = y * (y * x);
} else if ((y <= -0.0011) || (!(y <= -4e-25) && (y <= 1.52e+85))) {
tmp = t + (y * z);
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -9.2e+105: tmp = y * (y * x) elif (y <= -0.0011) or (not (y <= -4e-25) and (y <= 1.52e+85)): tmp = t + (y * z) else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -9.2e+105) tmp = Float64(y * Float64(y * x)); elseif ((y <= -0.0011) || (!(y <= -4e-25) && (y <= 1.52e+85))) tmp = Float64(t + Float64(y * z)); else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -9.2e+105) tmp = y * (y * x); elseif ((y <= -0.0011) || (~((y <= -4e-25)) && (y <= 1.52e+85))) tmp = t + (y * z); else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -9.2e+105], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -0.0011], And[N[Not[LessEqual[y, -4e-25]], $MachinePrecision], LessEqual[y, 1.52e+85]]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+105}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \leq -0.0011 \lor \neg \left(y \leq -4 \cdot 10^{-25}\right) \land y \leq 1.52 \cdot 10^{+85}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -9.1999999999999991e105Initial program 99.9%
Taylor expanded in t around inf 89.3%
Taylor expanded in y around inf 70.7%
unpow270.7%
*-commutative70.7%
associate-*r*86.0%
Simplified86.0%
if -9.1999999999999991e105 < y < -0.00110000000000000007 or -4.00000000000000015e-25 < y < 1.52e85Initial program 100.0%
Taylor expanded in x around 0 85.2%
if -0.00110000000000000007 < y < -4.00000000000000015e-25 or 1.52e85 < y Initial program 99.8%
Taylor expanded in t around inf 89.9%
Taylor expanded in y around inf 77.3%
unpow277.3%
*-commutative77.3%
associate-*r*76.9%
Simplified76.9%
associate-*r*77.3%
Applied egg-rr77.3%
Final simplification83.9%
(FPCore (x y z t)
:precision binary64
(if (<= y -3.3e+56)
(* y (* y x))
(if (<= y -60.0)
(* y z)
(if (or (<= y -9.5e-26) (not (<= y 1.05e+20))) (* x (* y y)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.3e+56) {
tmp = y * (y * x);
} else if (y <= -60.0) {
tmp = y * z;
} else if ((y <= -9.5e-26) || !(y <= 1.05e+20)) {
tmp = x * (y * 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 <= (-3.3d+56)) then
tmp = y * (y * x)
else if (y <= (-60.0d0)) then
tmp = y * z
else if ((y <= (-9.5d-26)) .or. (.not. (y <= 1.05d+20))) then
tmp = x * (y * 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 <= -3.3e+56) {
tmp = y * (y * x);
} else if (y <= -60.0) {
tmp = y * z;
} else if ((y <= -9.5e-26) || !(y <= 1.05e+20)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3.3e+56: tmp = y * (y * x) elif y <= -60.0: tmp = y * z elif (y <= -9.5e-26) or not (y <= 1.05e+20): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3.3e+56) tmp = Float64(y * Float64(y * x)); elseif (y <= -60.0) tmp = Float64(y * z); elseif ((y <= -9.5e-26) || !(y <= 1.05e+20)) tmp = Float64(x * Float64(y * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -3.3e+56) tmp = y * (y * x); elseif (y <= -60.0) tmp = y * z; elseif ((y <= -9.5e-26) || ~((y <= 1.05e+20))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.3e+56], N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -60.0], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -9.5e-26], N[Not[LessEqual[y, 1.05e+20]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+56}:\\
\;\;\;\;y \cdot \left(y \cdot x\right)\\
\mathbf{elif}\;y \leq -60:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-26} \lor \neg \left(y \leq 1.05 \cdot 10^{+20}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -3.30000000000000002e56Initial program 99.9%
Taylor expanded in t around inf 89.8%
Taylor expanded in y around inf 62.7%
unpow262.7%
*-commutative62.7%
associate-*r*74.4%
Simplified74.4%
if -3.30000000000000002e56 < y < -60Initial program 100.0%
Taylor expanded in z around inf 53.8%
if -60 < y < -9.4999999999999995e-26 or 1.05e20 < y Initial program 99.9%
Taylor expanded in t around inf 88.9%
Taylor expanded in y around inf 67.0%
unpow267.0%
*-commutative67.0%
associate-*r*66.8%
Simplified66.8%
associate-*r*67.0%
Applied egg-rr67.0%
if -9.4999999999999995e-26 < y < 1.05e20Initial program 100.0%
Taylor expanded in y around 0 67.0%
Final simplification67.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* y x))))
(if (<= y -2.75e+56)
t_1
(if (<= y -38.0)
(* y z)
(if (or (<= y -2e-26) (not (<= y 4.3e+21))) t_1 t)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (y * x);
double tmp;
if (y <= -2.75e+56) {
tmp = t_1;
} else if (y <= -38.0) {
tmp = y * z;
} else if ((y <= -2e-26) || !(y <= 4.3e+21)) {
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 * (y * x)
if (y <= (-2.75d+56)) then
tmp = t_1
else if (y <= (-38.0d0)) then
tmp = y * z
else if ((y <= (-2d-26)) .or. (.not. (y <= 4.3d+21))) 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 * (y * x);
double tmp;
if (y <= -2.75e+56) {
tmp = t_1;
} else if (y <= -38.0) {
tmp = y * z;
} else if ((y <= -2e-26) || !(y <= 4.3e+21)) {
tmp = t_1;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (y * x) tmp = 0 if y <= -2.75e+56: tmp = t_1 elif y <= -38.0: tmp = y * z elif (y <= -2e-26) or not (y <= 4.3e+21): tmp = t_1 else: tmp = t return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(y * x)) tmp = 0.0 if (y <= -2.75e+56) tmp = t_1; elseif (y <= -38.0) tmp = Float64(y * z); elseif ((y <= -2e-26) || !(y <= 4.3e+21)) tmp = t_1; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (y * x); tmp = 0.0; if (y <= -2.75e+56) tmp = t_1; elseif (y <= -38.0) tmp = y * z; elseif ((y <= -2e-26) || ~((y <= 4.3e+21))) tmp = t_1; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.75e+56], t$95$1, If[LessEqual[y, -38.0], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -2e-26], N[Not[LessEqual[y, 4.3e+21]], $MachinePrecision]], t$95$1, t]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -2.75 \cdot 10^{+56}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -38:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2 \cdot 10^{-26} \lor \neg \left(y \leq 4.3 \cdot 10^{+21}\right):\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -2.7500000000000001e56 or -38 < y < -2.0000000000000001e-26 or 4.3e21 < y Initial program 99.9%
Taylor expanded in t around inf 89.3%
Taylor expanded in y around inf 65.3%
unpow265.3%
*-commutative65.3%
associate-*r*69.9%
Simplified69.9%
if -2.7500000000000001e56 < y < -38Initial program 100.0%
Taylor expanded in z around inf 53.8%
if -2.0000000000000001e-26 < y < 4.3e21Initial program 100.0%
Taylor expanded in y around 0 67.0%
Final simplification67.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.8e-25) (not (<= y 5.5e+18))) (* y (+ z (* y x))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.8e-25) || !(y <= 5.5e+18)) {
tmp = y * (z + (y * x));
} 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-25)) .or. (.not. (y <= 5.5d+18))) then
tmp = y * (z + (y * x))
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-25) || !(y <= 5.5e+18)) {
tmp = y * (z + (y * x));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.8e-25) or not (y <= 5.5e+18): tmp = y * (z + (y * x)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.8e-25) || !(y <= 5.5e+18)) tmp = Float64(y * Float64(z + Float64(y * x))); 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-25) || ~((y <= 5.5e+18))) tmp = y * (z + (y * x)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.8e-25], N[Not[LessEqual[y, 5.5e+18]], $MachinePrecision]], N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-25} \lor \neg \left(y \leq 5.5 \cdot 10^{+18}\right):\\
\;\;\;\;y \cdot \left(z + y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.8e-25 or 5.5e18 < y Initial program 99.9%
Taylor expanded in t around 0 85.9%
if -1.8e-25 < y < 5.5e18Initial program 100.0%
Taylor expanded in x around 0 92.3%
Final simplification89.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.5e+137) (not (<= z 6.6e+109))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.5e+137) || !(z <= 6.6e+109)) {
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 <= (-2.5d+137)) .or. (.not. (z <= 6.6d+109))) 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 <= -2.5e+137) || !(z <= 6.6e+109)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.5e+137) or not (z <= 6.6e+109): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.5e+137) || !(z <= 6.6e+109)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.5e+137) || ~((z <= 6.6e+109))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.5e+137], N[Not[LessEqual[z, 6.6e+109]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+137} \lor \neg \left(z \leq 6.6 \cdot 10^{+109}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.5000000000000001e137 or 6.5999999999999998e109 < z Initial program 100.0%
Taylor expanded in z around inf 73.4%
if -2.5000000000000001e137 < z < 6.5999999999999998e109Initial program 99.9%
Taylor expanded in y around 0 48.2%
Final simplification55.3%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* y x)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
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 + (y * x)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
def code(x, y, z, t): return t + (y * (z + (y * x)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(y * x)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (y * x))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + y \cdot x\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 40.8%
herbie shell --seed 2024097
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))