
(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 100.0%
fma-def100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.3e+32) (not (<= y 230000.0))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.3e+32) || !(y <= 230000.0)) {
tmp = y * (z + (x * 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 ((y <= (-1.3d+32)) .or. (.not. (y <= 230000.0d0))) then
tmp = y * (z + (x * 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 ((y <= -1.3e+32) || !(y <= 230000.0)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.3e+32) or not (y <= 230000.0): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.3e+32) || !(y <= 230000.0)) tmp = Float64(y * Float64(z + Float64(x * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.3e+32) || ~((y <= 230000.0))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.3e+32], N[Not[LessEqual[y, 230000.0]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+32} \lor \neg \left(y \leq 230000\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.3000000000000001e32 or 2.3e5 < y Initial program 99.9%
Taylor expanded in t around 0 89.6%
if -1.3000000000000001e32 < y < 2.3e5Initial program 100.0%
Taylor expanded in x around 0 89.9%
Final simplification89.7%
(FPCore (x y z t) :precision binary64 (if (<= z -4e+98) (+ t (* y z)) (if (<= z 6.2e+34) (+ t (* y (* x y))) (* y (+ z (* x y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4e+98) {
tmp = t + (y * z);
} else if (z <= 6.2e+34) {
tmp = t + (y * (x * y));
} else {
tmp = y * (z + (x * y));
}
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 <= (-4d+98)) then
tmp = t + (y * z)
else if (z <= 6.2d+34) then
tmp = t + (y * (x * y))
else
tmp = y * (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4e+98) {
tmp = t + (y * z);
} else if (z <= 6.2e+34) {
tmp = t + (y * (x * y));
} else {
tmp = y * (z + (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -4e+98: tmp = t + (y * z) elif z <= 6.2e+34: tmp = t + (y * (x * y)) else: tmp = y * (z + (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -4e+98) tmp = Float64(t + Float64(y * z)); elseif (z <= 6.2e+34) tmp = Float64(t + Float64(y * Float64(x * y))); else tmp = Float64(y * Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -4e+98) tmp = t + (y * z); elseif (z <= 6.2e+34) tmp = t + (y * (x * y)); else tmp = y * (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -4e+98], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.2e+34], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+98}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+34}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if z < -3.99999999999999999e98Initial program 100.0%
Taylor expanded in x around 0 93.0%
if -3.99999999999999999e98 < z < 6.19999999999999955e34Initial program 99.9%
add-sqr-sqrt63.1%
pow263.1%
*-commutative63.1%
fma-def63.1%
Applied egg-rr63.1%
Taylor expanded in y around inf 49.1%
unpow249.1%
swap-sqr45.5%
add-sqr-sqrt87.2%
associate-*r*92.5%
Applied egg-rr92.5%
if 6.19999999999999955e34 < z Initial program 100.0%
Taylor expanded in t around 0 84.3%
Final simplification90.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.2e+179) (not (<= z 1.95e+15))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.2e+179) || !(z <= 1.95e+15)) {
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 ((z <= (-6.2d+179)) .or. (.not. (z <= 1.95d+15))) 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 ((z <= -6.2e+179) || !(z <= 1.95e+15)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.2e+179) or not (z <= 1.95e+15): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.2e+179) || !(z <= 1.95e+15)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -6.2e+179) || ~((z <= 1.95e+15))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.2e+179], N[Not[LessEqual[z, 1.95e+15]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+179} \lor \neg \left(z \leq 1.95 \cdot 10^{+15}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -6.2e179 or 1.95e15 < z Initial program 100.0%
Taylor expanded in x around 0 79.7%
Taylor expanded in y around inf 62.8%
if -6.2e179 < z < 1.95e15Initial program 99.9%
Taylor expanded in y around 0 49.6%
Final simplification54.2%
(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 100.0%
Final simplification100.0%
(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 100.0%
Taylor expanded in x around 0 67.0%
Final simplification67.0%
(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 100.0%
Taylor expanded in y around 0 38.5%
Final simplification38.5%
herbie shell --seed 2024031
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))