
(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 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
fma-define100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.85e-96) (not (<= x 2e-63))) (+ t (* x (* y y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.85e-96) || !(x <= 2e-63)) {
tmp = t + (x * (y * y));
} else {
tmp = t + (y * z);
}
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 ((x <= (-1.85d-96)) .or. (.not. (x <= 2d-63))) then
tmp = t + (x * (y * y))
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.85e-96) || !(x <= 2e-63)) {
tmp = t + (x * (y * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.85e-96) or not (x <= 2e-63): tmp = t + (x * (y * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.85e-96) || !(x <= 2e-63)) tmp = Float64(t + Float64(x * Float64(y * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.85e-96) || ~((x <= 2e-63))) tmp = t + (x * (y * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.85e-96], N[Not[LessEqual[x, 2e-63]], $MachinePrecision]], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-96} \lor \neg \left(x \leq 2 \cdot 10^{-63}\right):\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if x < -1.84999999999999993e-96 or 2.00000000000000013e-63 < x Initial program 100.0%
Taylor expanded in x around inf 93.7%
+-commutative93.7%
unpow293.7%
associate-/l*96.8%
distribute-lft-out98.1%
Simplified98.1%
Taylor expanded in y around inf 87.0%
if -1.84999999999999993e-96 < x < 2.00000000000000013e-63Initial program 99.9%
Taylor expanded in x around 0 86.7%
Final simplification86.8%
(FPCore (x y z t) :precision binary64 (if (<= z -2.65e+57) (+ t (* y z)) (if (<= z 1.06e+146) (+ t (* y (* x y))) (* z (+ y (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.65e+57) {
tmp = t + (y * z);
} else if (z <= 1.06e+146) {
tmp = t + (y * (x * y));
} else {
tmp = z * (y + (t / z));
}
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 <= (-2.65d+57)) then
tmp = t + (y * z)
else if (z <= 1.06d+146) then
tmp = t + (y * (x * y))
else
tmp = z * (y + (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.65e+57) {
tmp = t + (y * z);
} else if (z <= 1.06e+146) {
tmp = t + (y * (x * y));
} else {
tmp = z * (y + (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.65e+57: tmp = t + (y * z) elif z <= 1.06e+146: tmp = t + (y * (x * y)) else: tmp = z * (y + (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.65e+57) tmp = Float64(t + Float64(y * z)); elseif (z <= 1.06e+146) tmp = Float64(t + Float64(y * Float64(x * y))); else tmp = Float64(z * Float64(y + Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.65e+57) tmp = t + (y * z); elseif (z <= 1.06e+146) tmp = t + (y * (x * y)); else tmp = z * (y + (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.65e+57], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.06e+146], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y + N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.65 \cdot 10^{+57}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 1.06 \cdot 10^{+146}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y + \frac{t}{z}\right)\\
\end{array}
\end{array}
if z < -2.64999999999999993e57Initial program 100.0%
Taylor expanded in x around 0 86.4%
if -2.64999999999999993e57 < z < 1.06000000000000005e146Initial program 99.9%
Taylor expanded in x around inf 89.7%
*-commutative89.7%
Simplified89.7%
if 1.06000000000000005e146 < z Initial program 100.0%
Taylor expanded in x around 0 96.9%
Taylor expanded in z around inf 96.9%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (if (<= t -42000000000.0) t (if (<= t 2.7e-113) (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -42000000000.0) {
tmp = t;
} else if (t <= 2.7e-113) {
tmp = y * z;
} else {
tmp = 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 (t <= (-42000000000.0d0)) then
tmp = t
else if (t <= 2.7d-113) then
tmp = y * z
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -42000000000.0) {
tmp = t;
} else if (t <= 2.7e-113) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -42000000000.0: tmp = t elif t <= 2.7e-113: tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -42000000000.0) tmp = t; elseif (t <= 2.7e-113) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -42000000000.0) tmp = t; elseif (t <= 2.7e-113) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -42000000000.0], t, If[LessEqual[t, 2.7e-113], N[(y * z), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -42000000000:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 2.7 \cdot 10^{-113}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -4.2e10 or 2.69999999999999996e-113 < t Initial program 100.0%
Taylor expanded in y around 0 54.1%
if -4.2e10 < t < 2.69999999999999996e-113Initial program 99.9%
Taylor expanded in x around 0 47.6%
Taylor expanded in z around inf 47.6%
Taylor expanded in y around inf 38.5%
Final simplification47.6%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (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 + (y * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\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 61.5%
Final simplification61.5%
(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%
Taylor expanded in y around 0 36.3%
herbie shell --seed 2024184
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))