
(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 (+ t (* (+ z (* y x)) y)))
double code(double x, double y, double z, double t) {
return t + ((z + (y * 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 + ((z + (y * x)) * y)
end function
public static double code(double x, double y, double z, double t) {
return t + ((z + (y * x)) * y);
}
def code(x, y, z, t): return t + ((z + (y * x)) * y)
function code(x, y, z, t) return Float64(t + Float64(Float64(z + Float64(y * x)) * y)) end
function tmp = code(x, y, z, t) tmp = t + ((z + (y * x)) * y); end
code[x_, y_, z_, t_] := N[(t + N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \left(z + y \cdot x\right) \cdot y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y)) (t_2 (* (fma y x z) y))) (if (<= t_1 -4e+137) t_2 (if (<= t_1 4e+172) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double t_2 = fma(y, x, z) * y;
double tmp;
if (t_1 <= -4e+137) {
tmp = t_2;
} else if (t_1 <= 4e+172) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(z + Float64(y * x)) * y) t_2 = Float64(fma(y, x, z) * y) tmp = 0.0 if (t_1 <= -4e+137) tmp = t_2; elseif (t_1 <= 4e+172) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+137], t$95$2, If[LessEqual[t$95$1, 4e+172], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
t_2 := \mathsf{fma}\left(y, x, z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+137}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.0000000000000001e137 or 4.0000000000000003e172 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
unpow2N/A
sqr-neg-revN/A
mul-1-negN/A
mul-1-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-commutativeN/A
*-commutativeN/A
associate-*r/N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
Applied rewrites97.0%
if -4.0000000000000001e137 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.0000000000000003e172Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6491.6
Applied rewrites91.6%
Final simplification94.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (* y x) y))) (if (<= y -2650000000.0) t_1 (if (<= y 1.85e+53) (fma z y t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (y * x) * y;
double tmp;
if (y <= -2650000000.0) {
tmp = t_1;
} else if (y <= 1.85e+53) {
tmp = fma(z, y, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(y * x) * y) tmp = 0.0 if (y <= -2650000000.0) tmp = t_1; elseif (y <= 1.85e+53) tmp = fma(z, y, t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2650000000.0], t$95$1, If[LessEqual[y, 1.85e+53], N[(z * y + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y \cdot x\right) \cdot y\\
\mathbf{if}\;y \leq -2650000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+53}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.65e9 or 1.85e53 < y Initial program 99.8%
Taylor expanded in y around inf
unpow2N/A
sqr-neg-revN/A
mul-1-negN/A
mul-1-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-commutativeN/A
*-commutativeN/A
associate-*r/N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
Applied rewrites92.3%
Taylor expanded in x around inf
Applied rewrites74.0%
if -2.65e9 < y < 1.85e53Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.7
Applied rewrites92.7%
Final simplification82.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.f6463.5
Applied rewrites63.5%
(FPCore (x y z t) :precision binary64 (* 1.0 t))
double code(double x, double y, double z, double t) {
return 1.0 * 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 = 1.0d0 * t
end function
public static double code(double x, double y, double z, double t) {
return 1.0 * t;
}
def code(x, y, z, t): return 1.0 * t
function code(x, y, z, t) return Float64(1.0 * t) end
function tmp = code(x, y, z, t) tmp = 1.0 * t; end
code[x_, y_, z_, t_] := N[(1.0 * t), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot t
\end{array}
Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
flip3-+N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
clear-numN/A
flip3-+N/A
lift-+.f64N/A
inv-powN/A
lower-pow.f6499.8
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6469.4
Applied rewrites69.4%
Taylor expanded in t around inf
Applied rewrites66.5%
Taylor expanded in x around 0
Applied rewrites31.9%
herbie shell --seed 2024298
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))