
(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 100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.4e+70) (not (<= z 6.2e+136))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.4e+70) || !(z <= 6.2e+136)) {
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 <= (-6.4d+70)) .or. (.not. (z <= 6.2d+136))) 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 <= -6.4e+70) || !(z <= 6.2e+136)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.4e+70) or not (z <= 6.2e+136): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.4e+70) || !(z <= 6.2e+136)) 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 <= -6.4e+70) || ~((z <= 6.2e+136))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.4e+70], N[Not[LessEqual[z, 6.2e+136]], $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 -6.4 \cdot 10^{+70} \lor \neg \left(z \leq 6.2 \cdot 10^{+136}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -6.4000000000000005e70 or 6.19999999999999967e136 < z Initial program 100.0%
Taylor expanded in x around 0 90.9%
if -6.4000000000000005e70 < z < 6.19999999999999967e136Initial program 99.9%
Taylor expanded in x around inf 91.3%
*-commutative91.3%
Simplified91.3%
Final simplification91.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.5e+66) (not (<= z 9.5e+134))) (+ t (* y z)) (+ t (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.5e+66) || !(z <= 9.5e+134)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (y * 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.5d+66)) .or. (.not. (z <= 9.5d+134))) then
tmp = t + (y * z)
else
tmp = t + (x * (y * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.5e+66) || !(z <= 9.5e+134)) {
tmp = t + (y * z);
} else {
tmp = t + (x * (y * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.5e+66) or not (z <= 9.5e+134): tmp = t + (y * z) else: tmp = t + (x * (y * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.5e+66) || !(z <= 9.5e+134)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(x * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.5e+66) || ~((z <= 9.5e+134))) tmp = t + (y * z); else tmp = t + (x * (y * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.5e+66], N[Not[LessEqual[z, 9.5e+134]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{+66} \lor \neg \left(z \leq 9.5 \cdot 10^{+134}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if z < -3.4999999999999997e66 or 9.5000000000000004e134 < z Initial program 100.0%
Taylor expanded in x around 0 90.9%
if -3.4999999999999997e66 < z < 9.5000000000000004e134Initial program 99.9%
Taylor expanded in x around inf 90.9%
+-commutative90.9%
unpow290.9%
associate-/l*91.4%
distribute-lft-out93.3%
Simplified93.3%
Taylor expanded in y around inf 88.0%
Final simplification88.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.1e-45) (not (<= y 3.2e+66))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.1e-45) || !(y <= 3.2e+66)) {
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 ((y <= (-4.1d-45)) .or. (.not. (y <= 3.2d+66))) 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 ((y <= -4.1e-45) || !(y <= 3.2e+66)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.1e-45) or not (y <= 3.2e+66): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.1e-45) || !(y <= 3.2e+66)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.1e-45) || ~((y <= 3.2e+66))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.1e-45], N[Not[LessEqual[y, 3.2e+66]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-45} \lor \neg \left(y \leq 3.2 \cdot 10^{+66}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -4.0999999999999999e-45 or 3.2e66 < y Initial program 100.0%
Taylor expanded in x around 0 42.7%
+-commutative42.7%
fma-define42.7%
Simplified42.7%
Taylor expanded in y around inf 42.7%
Taylor expanded in z around inf 38.2%
if -4.0999999999999999e-45 < y < 3.2e66Initial program 100.0%
Taylor expanded in y around 0 71.9%
Final simplification55.1%
(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 100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (+ t (* y z)))
double code(double x, double y, double z, double t) {
return t + (y * z);
}
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)
end function
public static double code(double x, double y, double z, double t) {
return t + (y * z);
}
def code(x, y, z, t): return t + (y * z)
function code(x, y, z, t) return Float64(t + Float64(y * z)) end
function tmp = code(x, y, z, t) tmp = t + (y * z); end
code[x_, y_, z_, t_] := N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 66.5%
Final simplification66.5%
(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 100.0%
Taylor expanded in y around 0 39.5%
herbie shell --seed 2024110
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))