
(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 (+ 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 -5e+89) t_2 (if (<= t_1 1e+150) (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 <= -5e+89) {
tmp = t_2;
} else if (t_1 <= 1e+150) {
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 <= -5e+89) tmp = t_2; elseif (t_1 <= 1e+150) 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, -5e+89], t$95$2, If[LessEqual[t$95$1, 1e+150], 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 -5 \cdot 10^{+89}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+150}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.99999999999999983e89 or 9.99999999999999981e149 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.8%
Taylor expanded in y around inf
unpow2N/A
associate-*l*N/A
distribute-rgt-inN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6493.7
Applied rewrites93.7%
if -4.99999999999999983e89 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.99999999999999981e149Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6489.1
Applied rewrites89.1%
Final simplification91.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ z (* y x)) y)))
(if (<= t_1 -1e+189)
(* (* y x) y)
(if (<= t_1 2e+272) (fma z y t) (* (* y y) x)))))
double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double tmp;
if (t_1 <= -1e+189) {
tmp = (y * x) * y;
} else if (t_1 <= 2e+272) {
tmp = fma(z, y, t);
} else {
tmp = (y * y) * x;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(z + Float64(y * x)) * y) tmp = 0.0 if (t_1 <= -1e+189) tmp = Float64(Float64(y * x) * y); elseif (t_1 <= 2e+272) tmp = fma(z, y, t); else tmp = Float64(Float64(y * y) * x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+189], N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$1, 2e+272], N[(z * y + t), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+189}:\\
\;\;\;\;\left(y \cdot x\right) \cdot y\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+272}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1e189Initial program 99.8%
Taylor expanded in y around inf
unpow2N/A
associate-*l*N/A
distribute-rgt-inN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6497.8
Applied rewrites97.8%
Taylor expanded in x around inf
Applied rewrites71.8%
if -1e189 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e272Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6483.7
Applied rewrites83.7%
if 2.0000000000000001e272 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6491.5
Applied rewrites91.5%
Final simplification82.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y)) (t_2 (* (* y x) y))) (if (<= t_1 -1e+189) t_2 (if (<= t_1 2e+272) (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 = (y * x) * y;
double tmp;
if (t_1 <= -1e+189) {
tmp = t_2;
} else if (t_1 <= 2e+272) {
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(Float64(y * x) * y) tmp = 0.0 if (t_1 <= -1e+189) tmp = t_2; elseif (t_1 <= 2e+272) 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), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+189], t$95$2, If[LessEqual[t$95$1, 2e+272], 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 := \left(y \cdot x\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+189}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+272}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1e189 or 2.0000000000000001e272 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
unpow2N/A
associate-*l*N/A
distribute-rgt-inN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.7
Applied rewrites98.7%
Taylor expanded in x around inf
Applied rewrites77.5%
if -1e189 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e272Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6483.7
Applied rewrites83.7%
Final simplification81.7%
(FPCore (x y z t) :precision binary64 (if (<= z -3.5e-17) (fma z y t) (if (<= z 1.15e+74) (fma (* y x) y t) (fma z y t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.5e-17) {
tmp = fma(z, y, t);
} else if (z <= 1.15e+74) {
tmp = fma((y * x), y, t);
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.5e-17) tmp = fma(z, y, t); elseif (z <= 1.15e+74) tmp = fma(Float64(y * x), y, t); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.5e-17], N[(z * y + t), $MachinePrecision], If[LessEqual[z, 1.15e+74], N[(N[(y * x), $MachinePrecision] * y + t), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+74}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if z < -3.5000000000000002e-17 or 1.1499999999999999e74 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.9
Applied rewrites87.9%
if -3.5000000000000002e-17 < z < 1.1499999999999999e74Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.1
Applied rewrites94.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 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6467.8
Applied rewrites67.8%
(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
unpow2N/A
associate-*l*N/A
distribute-rgt-inN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-commutativeN/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6462.0
Applied rewrites62.0%
Taylor expanded in x around 0
Applied rewrites30.3%
herbie shell --seed 2024331
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))