
(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 (fma y x z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(y, x, z), y, t);
}
function code(x, y, z, t) return fma(fma(y, x, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(y * x + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(y, x, z\right), y, t\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ (* x y) z) y)))
(if (or (<= t_1 -5e+138) (not (<= t_1 5e+154)))
(* (fma y x z) y)
(fma z y t))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double tmp;
if ((t_1 <= -5e+138) || !(t_1 <= 5e+154)) {
tmp = fma(y, x, z) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) tmp = 0.0 if ((t_1 <= -5e+138) || !(t_1 <= 5e+154)) tmp = Float64(fma(y, x, z) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+138], N[Not[LessEqual[t$95$1, 5e+154]], $MachinePrecision]], N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+138} \lor \neg \left(t\_1 \leq 5 \cdot 10^{+154}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -5.00000000000000016e138 or 5.00000000000000004e154 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites96.3%
if -5.00000000000000016e138 < (*.f64 (+.f64 (*.f64 x y) z) y) < 5.00000000000000004e154Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.7
Applied rewrites90.7%
Final simplification93.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.5e+93) (not (<= y 7.2e+110))) (* (* x y) y) (fma z y t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.5e+93) || !(y <= 7.2e+110)) {
tmp = (x * y) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.5e+93) || !(y <= 7.2e+110)) tmp = Float64(Float64(x * y) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.5e+93], N[Not[LessEqual[y, 7.2e+110]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+93} \lor \neg \left(y \leq 7.2 \cdot 10^{+110}\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if y < -6.4999999999999998e93 or 7.1999999999999994e110 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6474.5
Applied rewrites74.5%
Applied rewrites81.9%
if -6.4999999999999998e93 < y < 7.1999999999999994e110Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.2
Applied rewrites88.2%
Final simplification86.1%
(FPCore (x y z t) :precision binary64 (fma z y t))
double code(double x, double y, double z, double t) {
return fma(z, y, t);
}
function code(x, y, z, t) return fma(z, y, t) end
code[x_, y_, z_, t_] := N[(z * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, t\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6469.4
Applied rewrites69.4%
(FPCore (x y z t) :precision binary64 (* z y))
double code(double x, double y, double z, double t) {
return z * 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 = z * y
end function
public static double code(double x, double y, double z, double t) {
return z * y;
}
def code(x, y, z, t): return z * y
function code(x, y, z, t) return Float64(z * y) end
function tmp = code(x, y, z, t) tmp = z * y; end
code[x_, y_, z_, t_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites62.8%
Taylor expanded in x around 0
Applied rewrites32.4%
herbie shell --seed 2024326
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))