
(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 6 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 (+ (* (+ (* 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}
Initial program 99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.4e+62) (not (<= y 3e-31))) (* (fma y x z) y) (fma z y t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.4e+62) || !(y <= 3e-31)) {
tmp = fma(y, x, z) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.4e+62) || !(y <= 3e-31)) tmp = Float64(fma(y, x, z) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.4e+62], N[Not[LessEqual[y, 3e-31]], $MachinePrecision]], N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+62} \lor \neg \left(y \leq 3 \cdot 10^{-31}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if y < -2.4e62 or 2.99999999999999981e-31 < y Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites90.6%
if -2.4e62 < y < 2.99999999999999981e-31Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.7
Applied rewrites92.7%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.2e+63) (not (<= y 1.6e+82))) (* (* y x) y) (fma z y t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.2e+63) || !(y <= 1.6e+82)) {
tmp = (y * x) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.2e+63) || !(y <= 1.6e+82)) tmp = Float64(Float64(y * x) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.2e+63], N[Not[LessEqual[y, 1.6e+82]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+63} \lor \neg \left(y \leq 1.6 \cdot 10^{+82}\right):\\
\;\;\;\;\left(y \cdot x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if y < -2.1999999999999999e63 or 1.59999999999999987e82 < y Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites95.2%
Taylor expanded in x around inf
Applied rewrites76.2%
if -2.1999999999999999e63 < y < 1.59999999999999987e82Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.0
Applied rewrites85.0%
Final simplification81.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.6e+65) (not (<= z 1.7e+36))) (* z y) (* 1.0 t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.6e+65) || !(z <= 1.7e+36)) {
tmp = z * y;
} else {
tmp = 1.0 * 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.6d+65)) .or. (.not. (z <= 1.7d+36))) then
tmp = z * y
else
tmp = 1.0d0 * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.6e+65) || !(z <= 1.7e+36)) {
tmp = z * y;
} else {
tmp = 1.0 * t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.6e+65) or not (z <= 1.7e+36): tmp = z * y else: tmp = 1.0 * t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.6e+65) || !(z <= 1.7e+36)) tmp = Float64(z * y); else tmp = Float64(1.0 * t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.6e+65) || ~((z <= 1.7e+36))) tmp = z * y; else tmp = 1.0 * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.6e+65], N[Not[LessEqual[z, 1.7e+36]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+65} \lor \neg \left(z \leq 1.7 \cdot 10^{+36}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot t\\
\end{array}
\end{array}
if z < -4.6e65 or 1.6999999999999999e36 < z Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites81.8%
Taylor expanded in x around 0
Applied rewrites63.7%
if -4.6e65 < z < 1.6999999999999999e36Initial program 99.9%
Taylor expanded in t around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower--.f64N/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-frac-negN/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6494.3
Applied rewrites94.3%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.3
Applied rewrites94.3%
Taylor expanded in y around 0
Applied rewrites49.0%
Final simplification55.9%
(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 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.5
Applied rewrites66.5%
(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 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites33.5%
herbie shell --seed 2024339
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))