Talk:LlList2ListStrided
Having some problems with this one, the page says:
"To get every second element in a "collection of data" in a strided list:" <lsl>llList2ListStrided(llDeleteSubList(src, 0, 0), 0, -1, 3);</lsl>
However that does not seem right, the last stride 3 should be a stride 2.
With an input list:
0.250000,a,0.250000,b,0.250000,c,0.250000,d
and using stride 3 instead of stride 2, I get:
a,0.250000,d
Using: <lsl>llList2ListStrided(llDeleteSubList(src, 0, 0), 0, -1, 2);</lsl> with a stride of 2 at the end instead, I get the expected result:
abcd
It makes sense to me: we are returning just the second element, so there is no need for a stride of 3, but rather a stride of 2 and the first element deleted.
I have changed it on the page, if I am wrong, please change it back.
Kira Komarov 07:11, 8 January 2012 (PST)
- There are a few problems with the article:
- A sample value of src was not provided.
- A description of src was not provided.
- The example fails to correlate the value 3 with any requirement for the structure of src or that it is important.
- For your example, using a strided list where the stride is 2 (and not 3) you need to set the llList2ListStride stride parameter as 2 (and not 3).
- Since fixing the example to match your usecase isn't going to help anyone with a say a stride of 4 we need to fix the example as to remove all underlying confusion. -- Strife (talk|contribs) 11:30, 8 January 2012 (PST)
Uhm, no...
Why do I even bother... Perhaps Linden should just put my account on hold again and put me out of my misery... Too many mobsters, I tell ya...
There are a few problems with the article
First, I have no clue what you are talking about Strife, you mean the src in my example? Or the src on the page? Since you want a "sample", I assume you are talking about the src in my example. Although I do say "with an input list":
0.250000,a,0.250000,b,0.250000,c,0.250000,d
So, I am not sure what you are talking about. What example? The example on the article page was broken (by Chaz Longstaff apparently at 11:06, 13 July 2008). That one?
For your example, using a strided list where the stride is 2 (and not 3) you need to set the llList2ListStride stride parameter as 2 (and not 3).
Thank you! Wait… Didn't I just say that in my first question? o.O
No, you need to use 2 instead of 3 for every example where you want to get every second element in a strided list.
Here is why:
- takes a paper out, puts a fist in her cheek and sighs deeply...*
Let S be an infinite abstract set of elements, such that:
S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... )
where s0, s1, s2, … are elements of the set S.
Let us assume that the set S is given by:
S = { i | i=[0, inf) }
where i is a number in the interval [0, inf).
We proceed to prove by induction that S gives us that set:
The base-case, for i=0:
S_{0} = ( s0 )
For i=1:
S_{1} = ( s1 )
For i=2:
S_{2} = ( s2 )
Which seems correct, thus let i->i+1:
S_{i+1} = { i+1 | i=[1, inf) }
However, since lists in computer science are indexed starting from zero, we subtract one from the indexer i, thus obtaining:
S_{i} = { i | i=[0, inf) }
which is exactly what we had to prove.
For kicks, let's run a few consistency checks:
S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... ) S_{0} = ( s0 ) S_{1} = ( s1 ) S_{2} = ( s2 ) S_{3} = ( s3 ) S_{4} = { s4 ) ...
Now, let S' be a new infinite abstract set, which will consist of every second (2-nd) element of the original set S:
S'= { 2i-1 | i=[0, inf) }
We proceed to prove by induction that S' gives us that set:
The base-case, for i=0:
S' = ( φ ) or, the element at index inf-1, in case of LSL wrap-around lists. This is why the code uses llDeleteList() to delete the first element.
For i=1:
S' = ( s1 )
For i=2:
S' = ( s3 )
Which seems correct, thus let i->i+1:
S'_{i+1} = { 2(i+1)-1 | i=[1, inf) }
However, since lists in computer science are indexed starting from zero, we subtract one from the indexer i, thus obtaining:
S'_{i} = { 2i-1 | i=[0, inf) }
which is exactly what we had to prove.
For kicks, let's run a few consistency checks:
S_{1} S_{2} S_{3} S_{4} | | | | | | | | . . . . S = ( s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13 ... ) S_{0} = ( φ ) S_{1} = ( s1 ) S_{2} = ( s3 ) S_{3} = ( s5 ) S_{4} = { s7 ) ...
One thing to note is that 2k+1 gives us odd numbers (2i+1 is what we would have gotten if we would not had subtracted one from the indexer):
k = 0 => i = 1 k = 1 => i = 3 k = 2 => i = 5 k = 3 => i = 7 ...
and 2k gives us even numbers:
k = 0 => i = 0 k = 1 => i = 2 k = 2 => i = 4 k = 3 => i = 6 ...
The set of (positive) integers N is defined by an union between the set of odd and even numbers:
E = { 2k | k = [0, inf) } set of even numbers O = { 2k+1 | k = [0, inf) ] set of odd numbers N = E U O
which gives us a set N (the natural number set) with every positive number without repetitions up to infinity. The same can be applied to the whole integer set Z, for negative numbers as well.
That is, by combining the few examples we have above, we get:
0, 1, 2, 3, 4, 5, 6, 7...
Similarly, another thing to note, is that the base-case k=0:
S'_{2 * 0 - 1} = S_{-1} = ( Φ )
gives us the empty set, or infinity-1 in LSL terms and that is why we delete the first element:
llList2ListStrided( llDeleteSubList(l, 0, 0) , 0, -1, 2); ^ | right here
Hence: <lsl> list S' = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 2); </lsl> is correct, instead of:
<lsl> list S' = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 3); </lsl> with '3, as it was written before on the wiki.
Example: <lsl> default {
state_entry() { list l = [0,1,2,3,4,5,6,7,8,9,10,11,12]; list s = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 2); llOwnerSay(llDumpList2String(s, " ")); }
} </lsl>
Output:
Object: 1 3 5 7 9 11
Counter-example, as the page was written before: <lsl> default {
state_entry() { list l = [0,1,2,3,4,5,6,7,8,9,10,11,12]; list s = llList2ListStrided(llDeleteSubList(l, 0, 0), 0, -1, 3); llOwnerSay(llDumpList2String(s, " ")); }
} </lsl>
Output:
Object: 1 4 7 10
Kira Komarov 13:11, 22 January 2012 (PST)
- I'm not seeing the disagreement here. If we have a list containing 3 strides with a width of 3 that are all [1,2,3] so the list is [1,2,3,1,2,3,1,2,3], llList2ListStrided(llDeleteSubList([1,2,3,1,2,3,1,2,3], 0, 0), 0, -1, 3) == [2,2,2]. Second element of each stride. If [2,2,2] isn't a list of the second elements of each stride (of 3) of [1,2,3,1,2,3,1,2,3], what is it? -- Strife (talk|contribs) 18:09, 22 January 2012 (PST)
Confusion in Notes Section
I find the wording in the notes section (under Ranges & Indexes ) to be a bit confusing. The reference to the "range operated on" is not clear. I am not sure what would be better but it should be made clear that they are referring to the collection of entries in a single stride. For example, the reference to the variable start as indicating the range to start on should say that it indicates which set of strides the operation begins.