
(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 (<= z -2.9e-5) (+ t (* y z)) (if (<= z 3.8e+155) (+ t (* y (* x y))) (* z (+ y (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.9e-5) {
tmp = t + (y * z);
} else if (z <= 3.8e+155) {
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 <= (-2.9d-5)) then
tmp = t + (y * z)
else if (z <= 3.8d+155) 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 <= -2.9e-5) {
tmp = t + (y * z);
} else if (z <= 3.8e+155) {
tmp = t + (y * (x * y));
} else {
tmp = z * (y + (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.9e-5: tmp = t + (y * z) elif z <= 3.8e+155: tmp = t + (y * (x * y)) else: tmp = z * (y + (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.9e-5) tmp = Float64(t + Float64(y * z)); elseif (z <= 3.8e+155) 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 <= -2.9e-5) tmp = t + (y * z); elseif (z <= 3.8e+155) tmp = t + (y * (x * y)); else tmp = z * (y + (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.9e-5], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.8e+155], 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 -2.9 \cdot 10^{-5}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{+155}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + \frac{t}{z}\right)\\
\end{array}
\end{array}
if z < -2.9e-5Initial program 100.0%
Taylor expanded in x around 0 86.5%
if -2.9e-5 < z < 3.8000000000000001e155Initial program 99.9%
Taylor expanded in x around inf 92.2%
*-commutative92.2%
Simplified92.2%
if 3.8000000000000001e155 < z Initial program 100.0%
Taylor expanded in x around 0 92.9%
Taylor expanded in z around inf 92.9%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (<= z -8.5e-6) (+ t (* y z)) (if (<= z 1.8e+156) (+ t (* x (* y y))) (* z (+ y (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -8.5e-6) {
tmp = t + (y * z);
} else if (z <= 1.8e+156) {
tmp = t + (x * (y * 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 <= (-8.5d-6)) then
tmp = t + (y * z)
else if (z <= 1.8d+156) then
tmp = t + (x * (y * 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 <= -8.5e-6) {
tmp = t + (y * z);
} else if (z <= 1.8e+156) {
tmp = t + (x * (y * y));
} else {
tmp = z * (y + (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -8.5e-6: tmp = t + (y * z) elif z <= 1.8e+156: tmp = t + (x * (y * y)) else: tmp = z * (y + (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -8.5e-6) tmp = Float64(t + Float64(y * z)); elseif (z <= 1.8e+156) tmp = Float64(t + Float64(x * Float64(y * 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 <= -8.5e-6) tmp = t + (y * z); elseif (z <= 1.8e+156) tmp = t + (x * (y * y)); else tmp = z * (y + (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -8.5e-6], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.8e+156], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y + N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-6}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+156}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + \frac{t}{z}\right)\\
\end{array}
\end{array}
if z < -8.4999999999999999e-6Initial program 100.0%
Taylor expanded in x around 0 86.5%
if -8.4999999999999999e-6 < z < 1.79999999999999989e156Initial program 99.9%
Taylor expanded in x around inf 88.2%
+-commutative88.2%
unpow288.2%
associate-/l*88.2%
distribute-lft-out91.0%
Simplified91.0%
Taylor expanded in y around inf 88.4%
if 1.79999999999999989e156 < z Initial program 100.0%
Taylor expanded in x around 0 92.9%
Taylor expanded in z around inf 92.9%
Final simplification88.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8e+156) (not (<= z 1.1e+156))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8e+156) || !(z <= 1.1e+156)) {
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 <= (-8d+156)) .or. (.not. (z <= 1.1d+156))) 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 <= -8e+156) || !(z <= 1.1e+156)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8e+156) or not (z <= 1.1e+156): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8e+156) || !(z <= 1.1e+156)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8e+156) || ~((z <= 1.1e+156))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8e+156], N[Not[LessEqual[z, 1.1e+156]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+156} \lor \neg \left(z \leq 1.1 \cdot 10^{+156}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -7.9999999999999999e156 or 1.10000000000000002e156 < z Initial program 100.0%
Taylor expanded in x around 0 93.2%
Taylor expanded in z around inf 93.2%
Taylor expanded in y around inf 76.3%
if -7.9999999999999999e156 < z < 1.10000000000000002e156Initial program 99.9%
Taylor expanded in y around 0 43.3%
Final simplification52.3%
(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.3%
Final simplification66.3%
(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 36.4%
herbie shell --seed 2024165
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))