
(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 7 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-define100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -1.6e+127)
t_1
(if (<= y -8.8e-27) (* y z) (if (<= y 0.0152) t t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -1.6e+127) {
tmp = t_1;
} else if (y <= -8.8e-27) {
tmp = y * z;
} else if (y <= 0.0152) {
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 = x * (y * y)
if (y <= (-1.6d+127)) then
tmp = t_1
else if (y <= (-8.8d-27)) then
tmp = y * z
else if (y <= 0.0152d0) 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 = x * (y * y);
double tmp;
if (y <= -1.6e+127) {
tmp = t_1;
} else if (y <= -8.8e-27) {
tmp = y * z;
} else if (y <= 0.0152) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -1.6e+127: tmp = t_1 elif y <= -8.8e-27: tmp = y * z elif y <= 0.0152: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -1.6e+127) tmp = t_1; elseif (y <= -8.8e-27) tmp = Float64(y * z); elseif (y <= 0.0152) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -1.6e+127) tmp = t_1; elseif (y <= -8.8e-27) tmp = y * z; elseif (y <= 0.0152) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.6e+127], t$95$1, If[LessEqual[y, -8.8e-27], N[(y * z), $MachinePrecision], If[LessEqual[y, 0.0152], t, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -1.6 \cdot 10^{+127}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{-27}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 0.0152:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.59999999999999988e127 or 0.0152 < y Initial program 99.9%
Taylor expanded in x around inf 69.9%
+-commutative69.9%
distribute-lft-in69.9%
unpow269.9%
associate-*l*79.5%
associate-/l*79.5%
associate-*r*73.8%
distribute-lft-out96.5%
*-commutative96.5%
Simplified96.5%
Taylor expanded in t around 0 82.8%
Taylor expanded in y around inf 72.7%
if -1.59999999999999988e127 < y < -8.79999999999999948e-27Initial program 99.9%
Taylor expanded in z around inf 92.7%
+-commutative92.7%
associate-/l*92.7%
fma-define92.7%
Simplified92.7%
Taylor expanded in y around inf 92.7%
associate-*l*92.7%
fma-define92.7%
distribute-rgt-in92.7%
*-commutative92.7%
lft-mult-inverse92.7%
Applied egg-rr92.7%
Taylor expanded in z around inf 59.1%
if -8.79999999999999948e-27 < y < 0.0152Initial program 100.0%
Taylor expanded in y around 0 67.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.1e+59) (not (<= z 7.4e+64))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e+59) || !(z <= 7.4e+64)) {
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 <= (-3.1d+59)) .or. (.not. (z <= 7.4d+64))) 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 <= -3.1e+59) || !(z <= 7.4e+64)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.1e+59) or not (z <= 7.4e+64): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.1e+59) || !(z <= 7.4e+64)) 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 <= -3.1e+59) || ~((z <= 7.4e+64))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.1e+59], N[Not[LessEqual[z, 7.4e+64]], $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 -3.1 \cdot 10^{+59} \lor \neg \left(z \leq 7.4 \cdot 10^{+64}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -3.10000000000000015e59 or 7.39999999999999966e64 < z Initial program 100.0%
Taylor expanded in x around 0 86.7%
if -3.10000000000000015e59 < z < 7.39999999999999966e64Initial program 99.9%
Taylor expanded in x around inf 92.1%
*-commutative92.1%
Simplified92.1%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.05e+127) (not (<= y 1.1e+63))) (* x (* y y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.05e+127) || !(y <= 1.1e+63)) {
tmp = x * (y * 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.05d+127)) .or. (.not. (y <= 1.1d+63))) then
tmp = x * (y * 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.05e+127) || !(y <= 1.1e+63)) {
tmp = x * (y * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.05e+127) or not (y <= 1.1e+63): tmp = x * (y * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.05e+127) || !(y <= 1.1e+63)) tmp = Float64(x * Float64(y * 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.05e+127) || ~((y <= 1.1e+63))) tmp = x * (y * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.05e+127], N[Not[LessEqual[y, 1.1e+63]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+127} \lor \neg \left(y \leq 1.1 \cdot 10^{+63}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.04999999999999991e127 or 1.0999999999999999e63 < y Initial program 99.9%
Taylor expanded in x around inf 68.4%
+-commutative68.4%
distribute-lft-in68.4%
unpow268.4%
associate-*l*79.5%
associate-/l*79.5%
associate-*r*72.9%
distribute-lft-out98.9%
*-commutative98.9%
Simplified98.9%
Taylor expanded in t around 0 87.2%
Taylor expanded in y around inf 76.9%
if -2.04999999999999991e127 < y < 1.0999999999999999e63Initial program 99.9%
Taylor expanded in x around 0 84.6%
Final simplification81.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.5e+89) (not (<= z 1.32e+56))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.5e+89) || !(z <= 1.32e+56)) {
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 <= (-1.5d+89)) .or. (.not. (z <= 1.32d+56))) 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 <= -1.5e+89) || !(z <= 1.32e+56)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.5e+89) or not (z <= 1.32e+56): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.5e+89) || !(z <= 1.32e+56)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.5e+89) || ~((z <= 1.32e+56))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.5e+89], N[Not[LessEqual[z, 1.32e+56]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+89} \lor \neg \left(z \leq 1.32 \cdot 10^{+56}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.50000000000000006e89 or 1.32e56 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
associate-/l*100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 99.9%
associate-*l*99.9%
fma-define99.9%
distribute-rgt-in99.9%
*-commutative99.9%
lft-mult-inverse100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 66.1%
if -1.50000000000000006e89 < z < 1.32e56Initial program 99.9%
Taylor expanded in y around 0 46.3%
Final simplification53.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 36.9%
herbie shell --seed 2024163
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))