Do programming languages have consistent interpretations of {1,...,n} when n = 0?
algorithm, math, oop, r, standards
Solution
Each mathematical formalism has its own notation. To suggest that there is a "universal notation" is very "un-mathematical". Look at the notation associated with tensors or groups if you want examples of mathematical domains where multiple notational systems exist.
In R the code `x <- 1:0` returns the ordered vector c(1,0). Just as the code x <- 2:-2 returns c(2,1,0,-1,-2). The code `x <- seq(1, length=0)` returns a sequence of length 0 which is printed in console sessions as `integer(0)`. R is not really designed to mimic set notation but it does have some set functions and it also has packages that more fully implement set notation.
Problem
On math.SE, a question about math notation enerated a discussion of how programming languages interpret the set {1,...,n} when n=0 The question asked for a mathematical notation to represent the R code `1:n` According to the comments, the mathematical interpretation of {1,...,n} when n=0 is that this is an empty set. A subsequent comment suggested that C is consistent with this interpretation, because `for (int i = 1; i < n; i++)` returns a empty set because it iterates 0 times. It is not clear to me what the equivalent statement in R is, but `1:0` returns the vector `[1,0]` Thus, `for (i in 1:0) print(i)` iterates over 1 and 0 (I interpret as analogous to the C code above) Is this because {1,...,n} is not the correct notation for `1:n`? Does this mean R violates a universal rule? Is there a consistent interpretation for this set among programming languages?