Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #6644

Re: generating permutations

From BartC <bc@freeuk.com>
Newsgroups comp.programming
Subject Re: generating permutations
Date 2016-05-23 14:09 +0100
Organization A noiseless patient Spider
Message-ID <nhuv7g$s2i$1@dont-email.me> (permalink)
References <86298170-5592-40fa-a275-7e90d472e2ce@googlegroups.com> <6d8de1c0-c835-4a67-b115-25249177e717@googlegroups.com> <ad4f7ce6-2699-42e3-815e-3ccce7c0200c@googlegroups.com>

Show all headers | View raw


On 22/05/2016 22:40, luser droog wrote:
> On Sunday, May 22, 2016 at 7:36:30 AM UTC-5, bart...@gmail.com wrote:
>> On Sunday, 22 May 2016 10:46:20 UTC+1, luser droog  wrote:
>>
>>> Maybe I'm getting ahead of my explanation. What I'm doing is, implementing
>>> the behavior for indexing an array with more than one number at an
>>> index position. I've got semicolons separating elements of the index
>>> vector and you can elide a position to select the entire dimension of
>>> the array.
>>>
>>>     a[;;1]   //select just column 1 from 3D table, yielding 2D table
>>>
>>> But I want to enable selecting an arbitrary collection of elements
>>> at each index.
>>>
>>>     a[0 3 5;;1]  //select items 0 3 5, all rows, column 1
>>>
>>> So, to have an indirect representation so it's still an l-value slice*
>>
>>
>>> * It needs to be an "l-value", indirectly referring to the original array
>>> so that an indexed expression can be the target of assignment.
>>> This already works for the simple slicing that is implemented.
>>
>> Simple slicing is easy, at least in one dimension. Your proposal sounds much more difficult. If you consider only a 2D array and allow any set of indices and ranges for each of the two dimensions, you will, in general, end up with a 2D matrix of separate sub-arrays. Each might be a single element, a short row or column, or a small matrix.
>>
>
> That is also possible. An element of an array can in fact be another array,
> but it's "concealed" behind its encoding as an atomic element.

No, I mean the result of your slicing can be an array, and perhaps lots 
of them, depending on how you pin down exactly what is meant by multiple 
slicing.

For example, take this is 2D array A of 3 rows of 5 columns:

((3 1 4 1 5)
  (9 2 6 5 3)
  (5 8 9 7 9)
  (3 2 3 8 4))

Assume indexing is one-based. A[2] is (9,2,6,5,3). A[2..3] is a slice 
consisting of the two rows:

  ((9,2,6,5,3),
   (5,8,8,7,9))

What about A[2..3;4] (using your semicolon method to separate 
dimensions)? Should it be the vertical vector (5,7)?

(I tried it on my language and that doesn't work, since arrays are 
1-dimensional: once A[2..3] yields the slice of two rows, then the 4 is 
out of bounds as it is operating on that slice, not the original array.)

With your true multi-dim arrays, then A[;4] presumably yields the column 
(1,5,7,8), while A[1 3 5;4] gives the column (1,7,8), and A[1 3 4;2 4] 
will give... now I'm lost! The A[1 3 4] is:

((3 1 4 1 5)
  (5 8 9 7 9)
  (3 2 3 8 4))

So adding ;2 4 might yield:

((1 1)
  (8 7)
  (2 8))

Nice and compact, perhaps the shape of your RHS on an assignment. But 
take a look at the original with just these highlighted:

((- 1 - 1 -)
  (- - - - -)
  (- 8 - 7 -)
  (- 2 - 8 -))

You selected 4 sub-arrays of the original: 2 individual elements, and 2 
column vectors of two elements each, arranged as a 2x2 array of 
sub-arrays; this is what I meant before. You're defining a rectangular 
matrix of sub-arrays using this slicing scheme.

(Note also that once you've created your complex multi-dimensional 
slice, someone might want to slice /that/!)

>> And can indices in the array be repeated? For example: a[2 2 2 2;] which returns 4 copies of element #2. This can make sense for an rvalue, but not for an lvalue.
>>
>
> That's a good point. I may want to flag arrays with duplicated ... what do
> you call those? ... referents along a dimension as not acceptable targets.

There's also ordering to consider: A[2 4 6] might give a different slice 
to A[6 4 2]. This can be useful for both lvalues and rvalues.

(I suppose it depends on whether the index for each dimension is a 
number, a range (ie. a normal slice from A to B), an ordered set, or a 
list, or ...)

-- 
Bartc

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-22 02:46 -0700
  Re: generating permutations bart4858@gmail.com - 2016-05-22 05:36 -0700
    Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-22 14:40 -0700
      Re: generating permutations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-22 22:58 +0100
      Re: generating permutations BartC <bc@freeuk.com> - 2016-05-23 14:09 +0100
        Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-23 21:36 -0700
          Re: generating permutations BartC <bc@freeuk.com> - 2016-05-24 12:56 +0100
            Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-25 19:03 -0700
              Re: generating permutations BartC <bc@freeuk.com> - 2016-05-26 13:08 +0100
                Re: generating permutations luser droog <mijoryx@yahoo.com> - 2016-05-26 08:35 -0700

csiph-web