[music-dsp] platform choice
robert bristow-johnson
rbj at audioimagination.com
Mon Nov 2 12:15:55 EST 2009
On Nov 2, 2009, at 5:22 AM, David Cournapeau wrote:
>
> The disagreement may come from our different way of looking at a
> computer and programming language. Most of the time, I could not care
> less about how a computer may 'think': the programming language is
> here to express my 'idea' of a certain algorithm, using the
> conventions from the concerned fields. I thought this was the
> convention we were talking about (i.e. in formula).
the issue is what MATLAB long ago used to put in their
> Now, for C, you *have* to start at 0,
no you don't.
> otherwise a[i] could not be the same as a + i.
double _a[2N+1], *a;
a = &(_a[N]);
for (n=-N; n<=N; n++)
{
do_something(a[n]);
}
> In that sense, I guess it is not a convention for the C
> programming language family. Most other programming languages, which
> are not as low level as C, do not have this restriction, since pointer
> and arrays are totally distinct.
the reason that zero-based arrays are more natural than 1-based
arrays is not so much that 0-based translates more directly to
machine language. see the Dijkstra missive:
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/
EWD831.html
> For those languages, it is a
> convention - and curiously, a lot of math-oriented 'languages' starts
> at one (matlab, R, Fortran, maybe Mathematica as well ?).
it's because, when we were kids, we first learned the term "natural
numbers" or "counting numbers" which were positive integers only.
then we learned the term "whole numbers" which were the non-negative
integers. then we learned about negative integers and the term
"integer".
> There are
> many engineering fields where the convention is to start at one: I
> have yet encountered a linear algebra book which count item starting
> at 0, and in statistics, you often represent N samples as (x_1, ....,
> x_N),
agreed. the 1-based convention seems natural and doesn't break
anything. try it with notation for convolution or the DFT. or for
polynomial coefficients.
--
r b-j rbj at audioimagination.com
"Imagination is more important than knowledge."
More information about the music-dsp
mailing list