Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
What is the notation supposed to mean? –  Chris Eagle Jun 7 '12 at 0:06
    
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. –  Egbert Jun 7 '12 at 0:10
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. –  MJD Jun 7 '12 at 0:21
    
@MarkDominus That sounds reasonable :) –  Egbert Jun 7 '12 at 0:25
    
@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. :) –  Rahul Jun 7 '12 at 0:42

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Would a specific example, e.g. $\{0.2,0.4,0.6,0.8\}$, require curly braces? –  Abe Jun 7 '12 at 0:35
    
I wouldn't. I would use some other sort of braces. –  MJD Jun 7 '12 at 1:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.