
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -9e-30)
t_1
(if (<= y -8.5e-145)
(* y z)
(if (<= y 6.2e-59)
t
(if (<= y 8.6e-8) (* y z) (if (<= y 3.5e+73) t t_1)))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -9e-30) {
tmp = t_1;
} else if (y <= -8.5e-145) {
tmp = y * z;
} else if (y <= 6.2e-59) {
tmp = t;
} else if (y <= 8.6e-8) {
tmp = y * z;
} else if (y <= 3.5e+73) {
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 <= (-9d-30)) then
tmp = t_1
else if (y <= (-8.5d-145)) then
tmp = y * z
else if (y <= 6.2d-59) then
tmp = t
else if (y <= 8.6d-8) then
tmp = y * z
else if (y <= 3.5d+73) 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 <= -9e-30) {
tmp = t_1;
} else if (y <= -8.5e-145) {
tmp = y * z;
} else if (y <= 6.2e-59) {
tmp = t;
} else if (y <= 8.6e-8) {
tmp = y * z;
} else if (y <= 3.5e+73) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -9e-30: tmp = t_1 elif y <= -8.5e-145: tmp = y * z elif y <= 6.2e-59: tmp = t elif y <= 8.6e-8: tmp = y * z elif y <= 3.5e+73: 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 <= -9e-30) tmp = t_1; elseif (y <= -8.5e-145) tmp = Float64(y * z); elseif (y <= 6.2e-59) tmp = t; elseif (y <= 8.6e-8) tmp = Float64(y * z); elseif (y <= 3.5e+73) 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 <= -9e-30) tmp = t_1; elseif (y <= -8.5e-145) tmp = y * z; elseif (y <= 6.2e-59) tmp = t; elseif (y <= 8.6e-8) tmp = y * z; elseif (y <= 3.5e+73) 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, -9e-30], t$95$1, If[LessEqual[y, -8.5e-145], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.2e-59], t, If[LessEqual[y, 8.6e-8], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.5e+73], t, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -9 \cdot 10^{-30}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-145}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-59}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{-8}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+73}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -8.99999999999999935e-30 or 3.50000000000000002e73 < y Initial program 99.9%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 93.1%
Taylor expanded in z around 0 67.4%
*-commutative67.4%
Simplified67.4%
if -8.99999999999999935e-30 < y < -8.50000000000000043e-145 or 6.19999999999999998e-59 < y < 8.6000000000000002e-8Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in t around 0 76.5%
Taylor expanded in z around inf 64.3%
if -8.50000000000000043e-145 < y < 6.19999999999999998e-59 or 8.6000000000000002e-8 < y < 3.50000000000000002e73Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 67.0%
Final simplification66.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.2e-60) (not (<= y 4e+39))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.2e-60) || !(y <= 4e+39)) {
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.2d-60)) .or. (.not. (y <= 4d+39))) 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.2e-60) || !(y <= 4e+39)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.2e-60) or not (y <= 4e+39): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.2e-60) || !(y <= 4e+39)) 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.2e-60) || ~((y <= 4e+39))) 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.2e-60], N[Not[LessEqual[y, 4e+39]], $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.2 \cdot 10^{-60} \lor \neg \left(y \leq 4 \cdot 10^{+39}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.19999999999999982e-60 or 3.99999999999999976e39 < y Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in t around 0 90.4%
if -4.19999999999999982e-60 < y < 3.99999999999999976e39Initial program 100.0%
Taylor expanded in x around 0 91.2%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.7e+94) (not (<= y 5.5e+75))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.7e+94) || !(y <= 5.5e+75)) {
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 <= (-4.7d+94)) .or. (.not. (y <= 5.5d+75))) 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 <= -4.7e+94) || !(y <= 5.5e+75)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.7e+94) or not (y <= 5.5e+75): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.7e+94) || !(y <= 5.5e+75)) 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 <= -4.7e+94) || ~((y <= 5.5e+75))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.7e+94], N[Not[LessEqual[y, 5.5e+75]], $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 -4.7 \cdot 10^{+94} \lor \neg \left(y \leq 5.5 \cdot 10^{+75}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.70000000000000017e94 or 5.5000000000000001e75 < y Initial program 99.9%
fma-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 98.8%
Taylor expanded in z around 0 73.5%
*-commutative73.5%
Simplified73.5%
if -4.70000000000000017e94 < y < 5.5000000000000001e75Initial program 99.9%
Taylor expanded in x around 0 83.1%
Final simplification79.8%
(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 -3.9e+134) (not (<= z 1.36e+70))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.9e+134) || !(z <= 1.36e+70)) {
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 <= (-3.9d+134)) .or. (.not. (z <= 1.36d+70))) 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 <= -3.9e+134) || !(z <= 1.36e+70)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.9e+134) or not (z <= 1.36e+70): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.9e+134) || !(z <= 1.36e+70)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.9e+134) || ~((z <= 1.36e+70))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.9e+134], N[Not[LessEqual[z, 1.36e+70]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.9 \cdot 10^{+134} \lor \neg \left(z \leq 1.36 \cdot 10^{+70}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -3.89999999999999983e134 or 1.35999999999999995e70 < z Initial program 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in t around 0 85.2%
Taylor expanded in z around inf 75.3%
if -3.89999999999999983e134 < z < 1.35999999999999995e70Initial program 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 46.1%
Final simplification56.8%
(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-def99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 35.3%
Final simplification35.3%
herbie shell --seed 2023334
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))