
(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.1e+32)
t_1
(if (<= y -7.6e-14) (* y z) (if (<= y 1.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.1e+32) {
tmp = t_1;
} else if (y <= -7.6e-14) {
tmp = y * z;
} else if (y <= 1.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.1d+32)) then
tmp = t_1
else if (y <= (-7.6d-14)) then
tmp = y * z
else if (y <= 1.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.1e+32) {
tmp = t_1;
} else if (y <= -7.6e-14) {
tmp = y * z;
} else if (y <= 1.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.1e+32: tmp = t_1 elif y <= -7.6e-14: tmp = y * z elif y <= 1.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.1e+32) tmp = t_1; elseif (y <= -7.6e-14) tmp = Float64(y * z); elseif (y <= 1.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.1e+32) tmp = t_1; elseif (y <= -7.6e-14) tmp = y * z; elseif (y <= 1.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.1e+32], t$95$1, If[LessEqual[y, -7.6e-14], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.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.1 \cdot 10^{+32}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -7.6 \cdot 10^{-14}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+24}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.1e32 or 1.90000000000000008e24 < y Initial program 99.9%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 90.2%
Taylor expanded in z around 0 75.2%
*-commutative75.2%
Simplified75.2%
if -1.1e32 < y < -7.6000000000000004e-14Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 81.3%
Taylor expanded in z around inf 64.3%
if -7.6000000000000004e-14 < y < 1.90000000000000008e24Initial program 99.9%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 70.7%
Final simplification72.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.2e-30) (not (<= y 4.1e+23))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.2e-30) || !(y <= 4.1e+23)) {
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 <= (-5.2d-30)) .or. (.not. (y <= 4.1d+23))) 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 <= -5.2e-30) || !(y <= 4.1e+23)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.2e-30) or not (y <= 4.1e+23): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.2e-30) || !(y <= 4.1e+23)) 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 <= -5.2e-30) || ~((y <= 4.1e+23))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.2e-30], N[Not[LessEqual[y, 4.1e+23]], $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 -5.2 \cdot 10^{-30} \lor \neg \left(y \leq 4.1 \cdot 10^{+23}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.19999999999999973e-30 or 4.09999999999999996e23 < y Initial program 99.9%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 88.5%
if -5.19999999999999973e-30 < y < 4.09999999999999996e23Initial program 100.0%
Taylor expanded in x around 0 90.4%
Final simplification89.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4e+93) (not (<= z 7.8e+120))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4e+93) || !(z <= 7.8e+120)) {
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 <= (-4d+93)) .or. (.not. (z <= 7.8d+120))) 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 <= -4e+93) || !(z <= 7.8e+120)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4e+93) or not (z <= 7.8e+120): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4e+93) || !(z <= 7.8e+120)) 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 <= -4e+93) || ~((z <= 7.8e+120))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4e+93], N[Not[LessEqual[z, 7.8e+120]], $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 -4 \cdot 10^{+93} \lor \neg \left(z \leq 7.8 \cdot 10^{+120}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -4.00000000000000017e93 or 7.7999999999999997e120 < z Initial program 100.0%
Taylor expanded in x around 0 87.4%
if -4.00000000000000017e93 < z < 7.7999999999999997e120Initial program 99.9%
Taylor expanded in x around inf 93.6%
*-commutative93.6%
Simplified93.6%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.4e+32) (not (<= y 4.7e+24))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.4e+32) || !(y <= 4.7e+24)) {
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 <= (-3.4d+32)) .or. (.not. (y <= 4.7d+24))) 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 <= -3.4e+32) || !(y <= 4.7e+24)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.4e+32) or not (y <= 4.7e+24): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.4e+32) || !(y <= 4.7e+24)) 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 <= -3.4e+32) || ~((y <= 4.7e+24))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.4e+32], N[Not[LessEqual[y, 4.7e+24]], $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 -3.4 \cdot 10^{+32} \lor \neg \left(y \leq 4.7 \cdot 10^{+24}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.39999999999999979e32 or 4.7e24 < y Initial program 99.9%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 90.2%
Taylor expanded in z around 0 75.8%
*-commutative75.8%
Simplified75.8%
if -3.39999999999999979e32 < y < 4.7e24Initial program 99.9%
Taylor expanded in x around 0 88.3%
Final simplification82.8%
(FPCore (x y z t) :precision binary64 (if (<= t -5.8e-91) t (if (<= t 4.1e-171) (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -5.8e-91) {
tmp = t;
} else if (t <= 4.1e-171) {
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 <= (-5.8d-91)) then
tmp = t
else if (t <= 4.1d-171) 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 <= -5.8e-91) {
tmp = t;
} else if (t <= 4.1e-171) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -5.8e-91: tmp = t elif t <= 4.1e-171: tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -5.8e-91) tmp = t; elseif (t <= 4.1e-171) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -5.8e-91) tmp = t; elseif (t <= 4.1e-171) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -5.8e-91], t, If[LessEqual[t, 4.1e-171], N[(y * z), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.8 \cdot 10^{-91}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 4.1 \cdot 10^{-171}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -5.8000000000000001e-91 or 4.1e-171 < t Initial program 99.9%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 52.9%
if -5.8000000000000001e-91 < t < 4.1e-171Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 92.8%
Taylor expanded in z around inf 47.3%
Final simplification51.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 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%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 42.1%
Final simplification42.1%
herbie shell --seed 2024018
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))