On Sat, Aug 1, 2009 at 4:20 AM, Raul Miller<[email protected]> wrote:
> On Sat, Aug 1, 2009 at 5:19 AM, Kip Murray<[email protected]> wrote:
>>    powerSet ''     NB. would like this to be <''
>> |length error: powerSet
>> |       powerSet''
>
>> Raul Miller wrote:
>>>    powerSet=: <@#~ 2#:@i...@^#
>
>
> Hmm... yes.
>   2^#''
> 1
>   #:i.1
> 0
>
> The problem is the traditional leading zero which
> we get from #: instead of a mathematically
> consistent empty list  of bits.
>

The problem looks to me, instead, that copy is sensitive to the axes
of the zero it receives when the argument to powerSet is empty.

   '' # 1 1$0
|length error
|   ''    #1 1$0

My approach would be to handle this edge case by returning a scalar
zero. Here's one way to do that:

   ec=: 0:`] @. (1<#)
   powerSet=: <@#~ ec@(2#:@i...@^#)

--
Tracy
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to