rmatlabnorm

Why is the default norm in R norm function the 1-norm?


Is there a reason for that the default norm used for the norm function in R is the 1-norm?

I was translating some code from matlab to R and I ran into this, because the default there is the 2-norm.

It just seems intuitive to me that the default should be the 2-norm, that translates to Euclidian distance.

I hope someone can clarify this, or give any historical reason for this choice. The reason I am asking this question is to understand implementation choices of the norm functions in matlab and R. The following is an implementation of norm in R

function (x, type = c("O", "I", "F", "M", "2")) 
{
    if (identical("2", type)) {
        svd(x, nu = 0L, nv = 0L)$d[1L]
    }
    else .Internal(La_dlange(x, type))
}

The default choice is "O". In matlab and python numpy the default is the 2-norm. It just seems weird to me that R is not consistent with that.

My gut feeling is that the implementation of the default option should correspond with the most used norm.


Solution

  • If R is related with LAPACK tightly, then the reason is simple. LAPACK is written in Fortran, which stores matrices column-wise, the 1-norm computing algorithm is column-oriented, so LAPACK tends to prefer 1-norm rather than other norms when there is a choice.

    In other words, to compute the norm fast, R delegates this task to LAPACK, where the fastest kind of norm to compute is the 1-norm.