
(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-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t) :precision binary64 (if (<= z -7.5e+54) (+ t (* y z)) (if (<= z 6.4e+115) (+ t (* y (* x y))) (* z (+ y (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -7.5e+54) {
tmp = t + (y * z);
} else if (z <= 6.4e+115) {
tmp = t + (y * (x * y));
} else {
tmp = z * (y + (t / 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 (z <= (-7.5d+54)) then
tmp = t + (y * z)
else if (z <= 6.4d+115) then
tmp = t + (y * (x * y))
else
tmp = z * (y + (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -7.5e+54) {
tmp = t + (y * z);
} else if (z <= 6.4e+115) {
tmp = t + (y * (x * y));
} else {
tmp = z * (y + (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -7.5e+54: tmp = t + (y * z) elif z <= 6.4e+115: tmp = t + (y * (x * y)) else: tmp = z * (y + (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -7.5e+54) tmp = Float64(t + Float64(y * z)); elseif (z <= 6.4e+115) tmp = Float64(t + Float64(y * Float64(x * y))); else tmp = Float64(z * Float64(y + Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -7.5e+54) tmp = t + (y * z); elseif (z <= 6.4e+115) tmp = t + (y * (x * y)); else tmp = z * (y + (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -7.5e+54], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.4e+115], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y + N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+54}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{+115}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + \frac{t}{z}\right)\\
\end{array}
\end{array}
if z < -7.50000000000000042e54Initial program 100.0%
Taylor expanded in x around 0 82.3%
if -7.50000000000000042e54 < z < 6.4e115Initial program 99.9%
Taylor expanded in x around inf 93.9%
*-commutative93.9%
Simplified93.9%
if 6.4e115 < z Initial program 100.0%
Taylor expanded in x around 0 85.3%
Taylor expanded in z around inf 85.3%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.4e+121) (not (<= y 1.6e-48))) (* x (* y y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e+121) || !(y <= 1.6e-48)) {
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.4d+121)) .or. (.not. (y <= 1.6d-48))) 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.4e+121) || !(y <= 1.6e-48)) {
tmp = x * (y * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.4e+121) or not (y <= 1.6e-48): tmp = x * (y * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.4e+121) || !(y <= 1.6e-48)) 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.4e+121) || ~((y <= 1.6e-48))) tmp = x * (y * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.4e+121], N[Not[LessEqual[y, 1.6e-48]], $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.4 \cdot 10^{+121} \lor \neg \left(y \leq 1.6 \cdot 10^{-48}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.4e121 or 1.5999999999999999e-48 < y Initial program 99.9%
Taylor expanded in x around inf 71.1%
+-commutative71.1%
distribute-lft-in70.2%
unpow270.2%
associate-*l*77.9%
associate-/l*77.1%
associate-*r*77.6%
distribute-lft-out97.3%
*-commutative97.3%
Simplified97.3%
Taylor expanded in t around 0 82.3%
Taylor expanded in y around inf 68.8%
if -2.4e121 < y < 1.5999999999999999e-48Initial program 99.9%
Taylor expanded in x around 0 81.1%
Final simplification75.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.5e-20) (not (<= y 2.2e-56))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.5e-20) || !(y <= 2.2e-56)) {
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 <= (-4.5d-20)) .or. (.not. (y <= 2.2d-56))) 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 <= -4.5e-20) || !(y <= 2.2e-56)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.5e-20) or not (y <= 2.2e-56): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.5e-20) || !(y <= 2.2e-56)) 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 <= -4.5e-20) || ~((y <= 2.2e-56))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.5e-20], N[Not[LessEqual[y, 2.2e-56]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-20} \lor \neg \left(y \leq 2.2 \cdot 10^{-56}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -4.5000000000000001e-20 or 2.20000000000000004e-56 < y Initial program 99.9%
Taylor expanded in x around inf 73.9%
+-commutative73.9%
distribute-lft-in73.2%
unpow273.2%
associate-*l*79.0%
associate-/l*78.3%
associate-*r*79.4%
distribute-lft-out94.8%
*-commutative94.8%
Simplified94.8%
Taylor expanded in t around 0 79.8%
Taylor expanded in y around inf 63.5%
if -4.5000000000000001e-20 < y < 2.20000000000000004e-56Initial program 100.0%
Taylor expanded in y around 0 65.3%
Final simplification64.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.8e+54) (not (<= z 5.8e-19))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.8e+54) || !(z <= 5.8e-19)) {
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 <= (-4.8d+54)) .or. (.not. (z <= 5.8d-19))) 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 <= -4.8e+54) || !(z <= 5.8e-19)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.8e+54) or not (z <= 5.8e-19): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.8e+54) || !(z <= 5.8e-19)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.8e+54) || ~((z <= 5.8e-19))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.8e+54], N[Not[LessEqual[z, 5.8e-19]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{+54} \lor \neg \left(z \leq 5.8 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -4.79999999999999997e54 or 5.8e-19 < z Initial program 100.0%
Taylor expanded in x around 0 75.9%
Taylor expanded in z around inf 75.8%
Taylor expanded in y around inf 57.9%
if -4.79999999999999997e54 < z < 5.8e-19Initial program 99.9%
Taylor expanded in y around 0 47.5%
Final simplification52.4%
(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 33.4%
herbie shell --seed 2024101
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))