
(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 8 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-def99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ t (* y z))) (t_2 (* y (+ z (* x y)))))
(if (<= y -1.7e-13)
t_2
(if (<= y 2.35e-70)
t_1
(if (<= y 4.5e-6)
(+ t (* x (* y y)))
(if (<= y 235000000.0) t_1 t_2))))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double t_2 = y * (z + (x * y));
double tmp;
if (y <= -1.7e-13) {
tmp = t_2;
} else if (y <= 2.35e-70) {
tmp = t_1;
} else if (y <= 4.5e-6) {
tmp = t + (x * (y * y));
} else if (y <= 235000000.0) {
tmp = t_1;
} else {
tmp = t_2;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = t + (y * z)
t_2 = y * (z + (x * y))
if (y <= (-1.7d-13)) then
tmp = t_2
else if (y <= 2.35d-70) then
tmp = t_1
else if (y <= 4.5d-6) then
tmp = t + (x * (y * y))
else if (y <= 235000000.0d0) then
tmp = t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = t + (y * z);
double t_2 = y * (z + (x * y));
double tmp;
if (y <= -1.7e-13) {
tmp = t_2;
} else if (y <= 2.35e-70) {
tmp = t_1;
} else if (y <= 4.5e-6) {
tmp = t + (x * (y * y));
} else if (y <= 235000000.0) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = t + (y * z) t_2 = y * (z + (x * y)) tmp = 0 if y <= -1.7e-13: tmp = t_2 elif y <= 2.35e-70: tmp = t_1 elif y <= 4.5e-6: tmp = t + (x * (y * y)) elif y <= 235000000.0: tmp = t_1 else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(t + Float64(y * z)) t_2 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -1.7e-13) tmp = t_2; elseif (y <= 2.35e-70) tmp = t_1; elseif (y <= 4.5e-6) tmp = Float64(t + Float64(x * Float64(y * y))); elseif (y <= 235000000.0) tmp = t_1; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = t + (y * z); t_2 = y * (z + (x * y)); tmp = 0.0; if (y <= -1.7e-13) tmp = t_2; elseif (y <= 2.35e-70) tmp = t_1; elseif (y <= 4.5e-6) tmp = t + (x * (y * y)); elseif (y <= 235000000.0) tmp = t_1; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e-13], t$95$2, If[LessEqual[y, 2.35e-70], t$95$1, If[LessEqual[y, 4.5e-6], N[(t + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 235000000.0], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot z\\
t_2 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{-13}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{-70}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-6}:\\
\;\;\;\;t + x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 235000000:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if y < -1.70000000000000008e-13 or 2.35e8 < y Initial program 99.9%
Taylor expanded in t around 0 94.9%
if -1.70000000000000008e-13 < y < 2.3499999999999999e-70 or 4.50000000000000011e-6 < y < 2.35e8Initial program 99.9%
Taylor expanded in x around 0 91.2%
if 2.3499999999999999e-70 < y < 4.50000000000000011e-6Initial program 99.9%
Taylor expanded in x around inf 87.4%
unpow287.4%
Simplified87.4%
Final simplification92.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -9e-13) (not (<= y 255000000.0))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9e-13) || !(y <= 255000000.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 <= (-9d-13)) .or. (.not. (y <= 255000000.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 <= -9e-13) || !(y <= 255000000.0)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -9e-13) or not (y <= 255000000.0): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -9e-13) || !(y <= 255000000.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 <= -9e-13) || ~((y <= 255000000.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, -9e-13], N[Not[LessEqual[y, 255000000.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 -9 \cdot 10^{-13} \lor \neg \left(y \leq 255000000\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -9e-13 or 2.55e8 < y Initial program 99.9%
Taylor expanded in t around 0 94.9%
if -9e-13 < y < 2.55e8Initial program 99.9%
Taylor expanded in x around 0 87.5%
Final simplification90.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.55e+49) (not (<= z 2.3e+71))) (+ t (* y z)) (+ t (* y (* x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.55e+49) || !(z <= 2.3e+71)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (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 <= (-1.55d+49)) .or. (.not. (z <= 2.3d+71))) then
tmp = t + (y * z)
else
tmp = t + (y * (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.55e+49) || !(z <= 2.3e+71)) {
tmp = t + (y * z);
} else {
tmp = t + (y * (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.55e+49) or not (z <= 2.3e+71): tmp = t + (y * z) else: tmp = t + (y * (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.55e+49) || !(z <= 2.3e+71)) tmp = Float64(t + Float64(y * z)); else tmp = Float64(t + Float64(y * Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.55e+49) || ~((z <= 2.3e+71))) tmp = t + (y * z); else tmp = t + (y * (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.55e+49], N[Not[LessEqual[z, 2.3e+71]], $MachinePrecision]], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+49} \lor \neg \left(z \leq 2.3 \cdot 10^{+71}\right):\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.54999999999999996e49 or 2.3000000000000002e71 < z Initial program 100.0%
Taylor expanded in x around 0 89.1%
if -1.54999999999999996e49 < z < 2.3000000000000002e71Initial program 99.9%
Taylor expanded in x around inf 95.2%
*-commutative95.2%
Simplified95.2%
Final simplification92.8%
(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 (if (<= z -1.5e+156) (* y z) (if (<= z 2.3e+119) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.5e+156) {
tmp = y * z;
} else if (z <= 2.3e+119) {
tmp = t;
} else {
tmp = 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 (z <= (-1.5d+156)) then
tmp = y * z
else if (z <= 2.3d+119) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.5e+156) {
tmp = y * z;
} else if (z <= 2.3e+119) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.5e+156: tmp = y * z elif z <= 2.3e+119: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.5e+156) tmp = Float64(y * z); elseif (z <= 2.3e+119) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.5e+156) tmp = y * z; elseif (z <= 2.3e+119) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.5e+156], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.3e+119], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+119}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.5e156 or 2.3000000000000001e119 < z Initial program 100.0%
Taylor expanded in t around 0 86.9%
Taylor expanded in y around 0 79.0%
if -1.5e156 < z < 2.3000000000000001e119Initial program 99.9%
Taylor expanded in y around 0 47.5%
Final simplification56.6%
(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 66.2%
Final simplification66.2%
(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 37.8%
Final simplification37.8%
herbie shell --seed 2023277
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))