  We generalize both the notion of polynomial functions on Lie groups and the
notion of horizontally affine maps on Carnot groups. We fix a subset $S$ of the
algebra $\mathfrak g$ of left-invariant vector fields on a Lie group $\mathbb
G$ and we assume that $S$ Lie generates $\mathfrak g$. We say that a function
$f:\mathbb G\to \mathbb R$ (or more generally a distribution on $\mathbb G$) is
$S$-polynomial if for all $X\in S$ there exists $k\in \mathbb N$ such that the
iterated derivative $X^k f$ is zero in the sense of distributions.
  First, we show that all $S$-polynomial functions (as well as distributions)
are represented by analytic functions and, if the exponent $k$ in the previous
definition is independent on $X\in S$, they form a finite-dimensional vector
space.
  Second, if $\mathbb G$ is connected and nilpotent we show that $S$-polynomial
functions are polynomial functions in the sense of Leibman. The same result may
not be true for non-nilpotent groups.
  Finally, we show that in connected nilpotent Lie groups, being polynomial in
the sense of Leibman, being a polynomial in exponential chart, and the
vanishing of mixed derivatives of some fixed degree along directions of
$\mathfrak g$ are equivalent notions.
