2
$\begingroup$

I am trying to explain R code:

(1:n)/(n+1) 

such that:

> n <- 4 > (1:n)/(n+1) [1] 0.2 0.4 0.6 0.8 

I might use

$$\frac{\{1, \ldots ,n\}}{n+1}$$

Is that okay? It seems to imply $n\neq1$. Does it?

  • 0
    What is the notation supposed to mean?2012-06-07
  • 0
    The notation $\{1,\ldots,n\}$ usually means the empty set when $n=0$. That's common practice in mathematics, but I don't know how well that translates to programming languages.2012-06-07
  • 1
    @Egbert Most programming languages do the same thing because otherwise you get really unexpected results. If you try to index some sequence value with `a[1 .. length(a)]` you get a bizarre answer for sequences of length 0 or 1 unless the definition of `..` follows the mathematical conventions.2012-06-07
  • 0
    @MarkDominus That sounds reasonable :)2012-06-07
  • 0
    @Egbert: Even in the not-particularly-mathematically-oriented C programming language, the usual idiom of iterating over the sequence $1,\ldots,n$ via `for (int i = 1; i <= n; i++)` performs exactly $n$ iterations even when $n$ is $0$ or $1$. I'd say $\{1,\ldots,n\}=\emptyset$ is a law of nature. :)2012-06-07
  • 0
    @RahulNarain in R, `1:0` returns the vector [1,0]2012-06-07
  • 0
    @Egbert, not sure if I understand fully, so I posted a [question on SE](http://stackoverflow.com/q/10924655/513006) to follow up on this discussion.2012-06-07

1 Answers 1

3

A lot of people are going to be completely mystified if you write $$\frac{\{1, ... ,n\}}{n+1}$$ I think you would do better to write this: $$\frac1{n+1},\cdots,\frac n{n+1}$$

Note that there are no curly braces, which would imply that the result was a set, rather than a sequence.

Perhaps you could write the first one if you first explained that it means the second one.

My suggestion does not imply $n\ne 1$. $n=1$ is perfectly okay, and in that case the expression means a sequence with one element.

R most likely generates an empty sequence when $n=0$; check this. If not, mention it explicitly. Depending on your audience, you might want to mention it anyway.

  • 0
    Would a specific example, e.g. $\{0.2,0.4,0.6,0.8\}$, require curly braces?2012-06-07
  • 0
    I wouldn't. I would use some other sort of braces.2012-06-07