
(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-def99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -1.02e-10)
t_1
(if (<= y 0.00056)
t
(if (<= y 5.5e+37)
t_1
(if (<= y 2.7e+47) t (if (<= y 1.6e+139) (* y z) t_1)))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.02e-10) {
tmp = t_1;
} else if (y <= 0.00056) {
tmp = t;
} else if (y <= 5.5e+37) {
tmp = t_1;
} else if (y <= 2.7e+47) {
tmp = t;
} else if (y <= 1.6e+139) {
tmp = y * z;
} 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.02d-10)) then
tmp = t_1
else if (y <= 0.00056d0) then
tmp = t
else if (y <= 5.5d+37) then
tmp = t_1
else if (y <= 2.7d+47) then
tmp = t
else if (y <= 1.6d+139) then
tmp = y * z
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.02e-10) {
tmp = t_1;
} else if (y <= 0.00056) {
tmp = t;
} else if (y <= 5.5e+37) {
tmp = t_1;
} else if (y <= 2.7e+47) {
tmp = t;
} else if (y <= 1.6e+139) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -1.02e-10: tmp = t_1 elif y <= 0.00056: tmp = t elif y <= 5.5e+37: tmp = t_1 elif y <= 2.7e+47: tmp = t elif y <= 1.6e+139: tmp = y * z 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.02e-10) tmp = t_1; elseif (y <= 0.00056) tmp = t; elseif (y <= 5.5e+37) tmp = t_1; elseif (y <= 2.7e+47) tmp = t; elseif (y <= 1.6e+139) tmp = Float64(y * z); 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.02e-10) tmp = t_1; elseif (y <= 0.00056) tmp = t; elseif (y <= 5.5e+37) tmp = t_1; elseif (y <= 2.7e+47) tmp = t; elseif (y <= 1.6e+139) tmp = y * z; 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.02e-10], t$95$1, If[LessEqual[y, 0.00056], t, If[LessEqual[y, 5.5e+37], t$95$1, If[LessEqual[y, 2.7e+47], t, If[LessEqual[y, 1.6e+139], N[(y * z), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.02 \cdot 10^{-10}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 0.00056:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+37}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+47}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+139}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.01999999999999997e-10 or 5.5999999999999995e-4 < y < 5.50000000000000016e37 or 1.6000000000000001e139 < y Initial program 99.9%
Taylor expanded in t around 0 91.9%
Taylor expanded in z around 0 77.1%
if -1.01999999999999997e-10 < y < 5.5999999999999995e-4 or 5.50000000000000016e37 < y < 2.69999999999999996e47Initial program 100.0%
Taylor expanded in y around 0 70.1%
if 2.69999999999999996e47 < y < 1.6000000000000001e139Initial program 99.9%
Taylor expanded in t around 0 94.8%
Taylor expanded in z around inf 68.2%
Final simplification73.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.8e-20) (not (<= y 8.2e-6))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.8e-20) || !(y <= 8.2e-6)) {
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 <= (-4.8d-20)) .or. (.not. (y <= 8.2d-6))) 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 <= -4.8e-20) || !(y <= 8.2e-6)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.8e-20) or not (y <= 8.2e-6): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.8e-20) || !(y <= 8.2e-6)) 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 <= -4.8e-20) || ~((y <= 8.2e-6))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.8e-20], N[Not[LessEqual[y, 8.2e-6]], $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 -4.8 \cdot 10^{-20} \lor \neg \left(y \leq 8.2 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.79999999999999986e-20 or 8.1999999999999994e-6 < y Initial program 99.9%
Taylor expanded in t around 0 90.1%
if -4.79999999999999986e-20 < y < 8.1999999999999994e-6Initial program 100.0%
Taylor expanded in x around 0 98.2%
Final simplification93.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.85e+65) (not (<= y 3e+139))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.85e+65) || !(y <= 3e+139)) {
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.85d+65)) .or. (.not. (y <= 3d+139))) 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.85e+65) || !(y <= 3e+139)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.85e+65) or not (y <= 3e+139): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.85e+65) || !(y <= 3e+139)) 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.85e+65) || ~((y <= 3e+139))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.85e+65], N[Not[LessEqual[y, 3e+139]], $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.85 \cdot 10^{+65} \lor \neg \left(y \leq 3 \cdot 10^{+139}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.85000000000000019e65 or 3e139 < y Initial program 99.9%
Taylor expanded in t around 0 96.9%
Taylor expanded in z around 0 83.9%
if -3.85000000000000019e65 < y < 3e139Initial program 99.9%
Taylor expanded in x around 0 86.7%
Final simplification85.6%
(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 (or (<= z -1.1e+92) (not (<= z 0.205))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.1e+92) || !(z <= 0.205)) {
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.1d+92)) .or. (.not. (z <= 0.205d0))) 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.1e+92) || !(z <= 0.205)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.1e+92) or not (z <= 0.205): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.1e+92) || !(z <= 0.205)) 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.1e+92) || ~((z <= 0.205))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.1e+92], N[Not[LessEqual[z, 0.205]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+92} \lor \neg \left(z \leq 0.205\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.09999999999999996e92 or 0.204999999999999988 < z Initial program 100.0%
Taylor expanded in t around 0 80.3%
Taylor expanded in z around inf 60.6%
if -1.09999999999999996e92 < z < 0.204999999999999988Initial program 99.9%
Taylor expanded in y around 0 47.9%
Final simplification53.6%
(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.2%
Final simplification36.2%
herbie shell --seed 2023301
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))