
(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-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (* y y))))
(if (<= y -250.0)
t_1
(if (<= y -1.1e-81) (* y z) (if (<= y 6e-11) t t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -250.0) {
tmp = t_1;
} else if (y <= -1.1e-81) {
tmp = y * z;
} else if (y <= 6e-11) {
tmp = t;
} else {
tmp = t_1;
}
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) :: tmp
t_1 = x * (y * y)
if (y <= (-250.0d0)) then
tmp = t_1
else if (y <= (-1.1d-81)) then
tmp = y * z
else if (y <= 6d-11) then
tmp = t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -250.0) {
tmp = t_1;
} else if (y <= -1.1e-81) {
tmp = y * z;
} else if (y <= 6e-11) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -250.0: tmp = t_1 elif y <= -1.1e-81: tmp = y * z elif y <= 6e-11: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -250.0) tmp = t_1; elseif (y <= -1.1e-81) tmp = Float64(y * z); elseif (y <= 6e-11) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -250.0) tmp = t_1; elseif (y <= -1.1e-81) tmp = y * z; elseif (y <= 6e-11) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -250.0], t$95$1, If[LessEqual[y, -1.1e-81], N[(y * z), $MachinePrecision], If[LessEqual[y, 6e-11], t, t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -250:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -1.1 \cdot 10^{-81}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-11}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -250 or 6e-11 < y Initial program 99.9%
Taylor expanded in x around inf 78.3%
+-commutative78.3%
unpow278.3%
associate-/l*81.9%
distribute-lft-out86.5%
Simplified86.5%
Taylor expanded in t around 0 78.1%
Taylor expanded in y around inf 66.7%
if -250 < y < -1.1e-81Initial program 100.0%
Taylor expanded in x around inf 91.0%
+-commutative91.0%
unpow291.0%
associate-/l*90.8%
distribute-lft-out90.8%
Simplified90.8%
Taylor expanded in t around 0 72.1%
Taylor expanded in x around 0 72.0%
if -1.1e-81 < y < 6e-11Initial program 99.9%
Taylor expanded in y around 0 66.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3400000.0) (not (<= y 2.75e-31))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3400000.0) || !(y <= 2.75e-31)) {
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 <= (-3400000.0d0)) .or. (.not. (y <= 2.75d-31))) 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 <= -3400000.0) || !(y <= 2.75e-31)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3400000.0) or not (y <= 2.75e-31): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3400000.0) || !(y <= 2.75e-31)) 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 <= -3400000.0) || ~((y <= 2.75e-31))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3400000.0], N[Not[LessEqual[y, 2.75e-31]], $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 -3400000 \lor \neg \left(y \leq 2.75 \cdot 10^{-31}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.4e6 or 2.74999999999999979e-31 < y Initial program 99.9%
Taylor expanded in x around inf 78.9%
+-commutative78.9%
unpow278.9%
associate-/l*82.5%
distribute-lft-out87.1%
Simplified87.1%
Taylor expanded in t around 0 78.6%
Taylor expanded in y around 0 90.4%
if -3.4e6 < y < 2.74999999999999979e-31Initial program 99.9%
Taylor expanded in x around 0 89.3%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.16e+63) (+ t (* y z)) (if (<= z 27500000.0) (+ t (* y (* x y))) (* y (+ z (* x y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.16e+63) {
tmp = t + (y * z);
} else if (z <= 27500000.0) {
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 <= (-1.16d+63)) then
tmp = t + (y * z)
else if (z <= 27500000.0d0) 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 <= -1.16e+63) {
tmp = t + (y * z);
} else if (z <= 27500000.0) {
tmp = t + (y * (x * y));
} else {
tmp = y * (z + (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.16e+63: tmp = t + (y * z) elif z <= 27500000.0: tmp = t + (y * (x * y)) else: tmp = y * (z + (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.16e+63) tmp = Float64(t + Float64(y * z)); elseif (z <= 27500000.0) 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 <= -1.16e+63) tmp = t + (y * z); elseif (z <= 27500000.0) tmp = t + (y * (x * y)); else tmp = y * (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.16e+63], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 27500000.0], 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 -1.16 \cdot 10^{+63}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 27500000:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if z < -1.15999999999999994e63Initial program 100.0%
Taylor expanded in x around 0 89.4%
if -1.15999999999999994e63 < z < 2.75e7Initial program 99.9%
Taylor expanded in x around inf 96.9%
*-commutative96.9%
Simplified96.9%
if 2.75e7 < z Initial program 99.9%
Taylor expanded in x around inf 62.4%
+-commutative62.4%
unpow262.4%
associate-/l*66.1%
distribute-lft-out72.0%
Simplified72.0%
Taylor expanded in t around 0 59.6%
Taylor expanded in y around 0 85.7%
Final simplification92.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.6e+23) (not (<= y 1.3e+71))) (* x (* y y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.6e+23) || !(y <= 1.3e+71)) {
tmp = 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 ((y <= (-2.6d+23)) .or. (.not. (y <= 1.3d+71))) then
tmp = 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 ((y <= -2.6e+23) || !(y <= 1.3e+71)) {
tmp = x * (y * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.6e+23) or not (y <= 1.3e+71): tmp = x * (y * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.6e+23) || !(y <= 1.3e+71)) tmp = 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 ((y <= -2.6e+23) || ~((y <= 1.3e+71))) tmp = x * (y * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.6e+23], N[Not[LessEqual[y, 1.3e+71]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+23} \lor \neg \left(y \leq 1.3 \cdot 10^{+71}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.59999999999999992e23 or 1.29999999999999996e71 < y Initial program 99.9%
Taylor expanded in x around inf 78.3%
+-commutative78.3%
unpow278.3%
associate-/l*82.5%
distribute-lft-out87.7%
Simplified87.7%
Taylor expanded in t around 0 79.6%
Taylor expanded in y around inf 69.9%
if -2.59999999999999992e23 < y < 1.29999999999999996e71Initial program 99.9%
Taylor expanded in x around 0 85.0%
Final simplification77.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.6e+38) (not (<= z 1100000000000.0))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.6e+38) || !(z <= 1100000000000.0)) {
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 <= (-2.6d+38)) .or. (.not. (z <= 1100000000000.0d0))) 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 <= -2.6e+38) || !(z <= 1100000000000.0)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.6e+38) or not (z <= 1100000000000.0): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.6e+38) || !(z <= 1100000000000.0)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.6e+38) || ~((z <= 1100000000000.0))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.6e+38], N[Not[LessEqual[z, 1100000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+38} \lor \neg \left(z \leq 1100000000000\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.5999999999999999e38 or 1.1e12 < z Initial program 99.9%
Taylor expanded in x around inf 73.6%
+-commutative73.6%
unpow273.6%
associate-/l*72.0%
distribute-lft-out77.3%
Simplified77.3%
Taylor expanded in t around 0 63.7%
Taylor expanded in x around 0 63.3%
if -2.5999999999999999e38 < z < 1.1e12Initial program 99.9%
Taylor expanded in y around 0 42.6%
Final simplification51.9%
(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)
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 32.9%
herbie shell --seed 2024150
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))