
(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 5 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 y (fma x y z) t))
double code(double x, double y, double z, double t) {
return fma(y, fma(x, y, z), t);
}
function code(x, y, z, t) return fma(y, fma(x, y, z), t) end
code[x_, y_, z_, t_] := N[(y * N[(x * y + z), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \mathsf{fma}\left(x, y, z\right), t\right)
\end{array}
Initial program 99.9%
*-commutative99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.2e+37) (not (<= z 1.4e+86))) (+ t (* y z)) (+ t (* y (* y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.2e+37) || !(z <= 1.4e+86)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (y * x));
}
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 <= (-9.2d+37)) .or. (.not. (z <= 1.4d+86))) then
tmp = t + (y * z)
else
tmp = t + (y * (y * x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.2e+37) || !(z <= 1.4e+86)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (y * x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9.2e+37) or not (z <= 1.4e+86): tmp = t + (y * z) else: tmp = t + (y * (y * x)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.2e+37) || !(z <= 1.4e+86)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(y * Float64(y * x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9.2e+37) || ~((z <= 1.4e+86))) tmp = t + (y * z); else tmp = t + (y * (y * x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.2e+37], N[Not[LessEqual[z, 1.4e+86]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+37} \lor \neg \left(z \leq 1.4 \cdot 10^{+86}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if z < -9.2000000000000001e37 or 1.40000000000000002e86 < z Initial program 100.0%
Taylor expanded in x around 0 88.1%
if -9.2000000000000001e37 < z < 1.40000000000000002e86Initial program 99.9%
Taylor expanded in x around inf 94.9%
*-commutative94.9%
Simplified94.9%
Final simplification91.9%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* y x)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
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 + (y * x)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (y * x)));
}
def code(x, y, z, t): return t + (y * (z + (y * x)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(y * x)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (y * x))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + y \cdot x\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(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 99.9%
Taylor expanded in x around 0 65.1%
Final simplification65.1%
(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%
*-commutative99.9%
fma-define99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 32.7%
herbie shell --seed 2024096
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))