So, this will probably just look like a lot of math, but I think it's what
you are trying to say:

We can consider the vector space over the real numbers consisting of all
infinite sequences of numbers with finitely many nonzero terms. So a member
of this space can be expressed as a finite list that ends where it starts
being zero, i.e.
1 5 2 8 0 <=> 1 5 2 8 0 0 0...
Note that the length of this vector is not an intrinsic property; it really
has infinite length, and if we add two (using the addition property that
comes with being a vector space), we may need to pad one or the other if we
are using a finite representation.

There is a family of projections from this vector space onto the real
numbers given by any base b, and which consist of summing the formal series
(b^i._) +/@:* v . This is the standard base formula #. , with left argument
b, except that I've reversed the direction of the sequence involved.

These projections are linear, so they have the property that (c*#.) -:
([:#.c&*) , and (dyadically) (+&#. -: #.@:+) .

Since the kernel of each such projection is a subspace of our vector space,
it defines a quotient space, which consists of all of the equivalence
classes of the space under equality of base. This quotient space has one
element for each real number.

The problem is that the quotient space is defined abstractly--it is no use
to us in actually finding vectors which represent a given number in our
base. If we have such a back-projection--and here's where your examples
come in--addition commutes with #. by linearity, so (+&.:(#.^:_1) -: ]) .
Therefore we have antibase, which attempts to find a representative vector
in the original space for each real number we give it. It's correct on the
nonnegative real numbers, and furthermore generates a unique vector for
each input up to initial zeros.

One approach to #: would simply be to return the number, with all zeros
after that. That is indeed a correct inverse, and furthermore is linear,
but it's useless, since it just spits the same number back. What we
actually want is to place some restrictions on the output. For nonnegative
integers and integers b>1, we can ensure that all of the digits of the
lifted vector are in (i.b) . For reals we use the integral representation
of the floor, but allow the last digit to be real (i.e. we take (#:<.r) +
((_#0) , 1|r)), maintaining that all digits are nonnegative and less than b.

For negative numbers this approach falls apart. The region of space we have
used for nonnegative numbers doesn't contain a representative for every
equivalence class. Therefore we need to pick a new space to work with if we
want to invert #. for negative numbers. That's what we've been trying to
do, and unlike nonnegative integers, there's no easy answer.

Marshall

On Wed, Dec 14, 2011 at 9:06 PM, Linda Alvord <lindaalv...@verizon.net>wrote:

> Let me try again.  I keep simplifying what I'm trying to explain.  So here
> it is again.  Maybe this will make some sense of what I'm saying:
>
>
>   ]a=:8+i.15
> 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
>
>   ]b=:15#15
> 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
>
>   ]c=:a-b
> _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7
>
>
>   f=: 13 :'(x#2)#:y'
>   f
> ] #:~ 2 #~ [
>
> The function f converts the lists to binary numbers.  The largest number
>  22
> is less than  32  so only  5  digits are require.
>
>  ]aa=:5 f a
> 0 1 0 0 0
> 0 1 0 0 1
> 0 1 0 1 0
> 0 1 0 1 1
> 0 1 1 0 0
> 0 1 1 0 1
> 0 1 1 1 0
> 0 1 1 1 1
> 1 0 0 0 0
> 1 0 0 0 1
> 1 0 0 1 0
> 1 0 0 1 1
> 1 0 1 0 0
> 1 0 1 0 1
> 1 0 1 1 0
>
>   ]bb=:5 f b
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
> 0 1 1 1 1
>
>  The result below is the difference in  J  between the two arrays above. It
> is not a conversion using  #:
>
>   ]cc=:aa-bb
> 0  0 _1 _1 _1
> 0  0 _1 _1  0
> 0  0 _1  0 _1
> 0  0 _1  0  0
> 0  0  0 _1 _1
> 0  0  0 _1  0
> 0  0  0  0 _1
> 0  0  0  0  0
> 1 _1 _1 _1 _1
> 1 _1 _1 _1  0
> 1 _1 _1  0 _1
> 1 _1 _1  0  0
> 1 _1  0 _1 _1
> 1 _1  0 _1  0
> 1 _1  0  0 _1
>
> For comparison, the result  cc2  is obtained  as a  J  result using  #:
>   ]cc2=: 5 f c
> 1 1 0 0 1
> 1 1 0 1 0
> 1 1 0 1 1
> 1 1 1 0 0
> 1 1 1 0 1
> 1 1 1 1 0
> 1 1 1 1 1
> 0 0 0 0 0
> 0 0 0 0 1
> 0 0 0 1 0
> 0 0 0 1 1
> 0 0 1 0 0
> 0 0 1 0 1
> 0 0 1 1 0
> 0 0 1 1 1
>
> Or:
>
>  ]cc3=:#:c
> 0 0 1
> 0 1 0
> 0 1 1
> 1 0 0
> 1 0 1
> 1 1 0
> 1 1 1
> 0 0 0
> 0 0 1
> 0 1 0
> 0 1 1
> 1 0 0
> 1 0 1
> 1 1 0
> 1 1 1
>
> Both cc2 and cc3 seem implausible because all numbers are known positive
> numbers. Now look at  cc :
>
>   w=: 13 :'(x,y)$|.2^i.y'
>   w
> , $ [: |. 2 ^ [: i. ]
>   15 w 5
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
> 16 8 4 2 1
>
>   cc*15 w 5
>  0  0 _4 _2 _1
>  0  0 _4 _2  0
>  0  0 _4  0 _1
>  0  0 _4  0  0
>  0  0  0 _2 _1
>  0  0  0 _2  0
>  0  0  0  0 _1
>  0  0  0  0  0
> 16 _8 _4 _2 _1
> 16 _8 _4 _2  0
> 16 _8 _4  0 _1
> 16 _8 _4  0  0
> 16 _8  0 _2 _1
> 16 _8  0 _2  0
> 16 _8  0  0 _1
>
>
>   +/"1 cc*15 w 5
> _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7
>
> This is c!
>
> Not only that,  J  knows it is c.
>
>   #.cc
> _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7
>
> So what do you think?
>
> Linda
>
>
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Devon McCormick
> Sent: Wednesday, December 14, 2011 5:04 PM
> To: Programming forum
> Subject: Re: [Jprogramming] How #: should have been designed
>
> So "8" would have to be represented by "0 1 0 0 0".
>
> On Wed, Dec 14, 2011 at 12:11 PM, Raul Miller <rauldmil...@gmail.com>
> wrote:
>
> > For two's complement to work, you need the leading bit to be 0 for
> > non-negative numbers.
> >
> > Limiting the range of considered numbers (as you would for a fixed
> > width bit sequence) is one tool you can use here.
> >
> > This can also be looked at as a padding issue (and the rude treatment
> > #:'s results get from frame fill can be motivating, for treating this
> > issue properly).
> >
> > --
> > Raul
> >
> > On Wed, Dec 14, 2011 at 11:02 AM, Devon McCormick <devon...@gmail.com>
> > wrote:
> > > The "embarassing" example happens because the full scope of "two's
> > > complement" notation implies fixed-width binary numbers, not the
> > > variable-width version given in this thread.
> > >
> > > On Wed, Dec 14, 2011 at 10:41 AM, Kip Murray <k...@math.uh.edu> wrote:
> > >
> > >> On 12/14/2011 6:07 AM, Linda Alvord wrote:
> > >> > I really don't think that you can ever write a program good enough
> > that
> > >> the
> > >> > the number  8 in binary is _8 in decimals
> > >> >
> > >> >       hcinv 1 0 0 0
> > >> >    _8
> > >>
> > >> THAT /IS/ EMBARRASSING !
> > >>
> > >> > I have lived my mathematical life without being able to write
> negative
> > >> > binary numbers. I have always ignored two's complements as beyond my
> > >> scope
> > >> > of interest.  It is like saying there are no negative numbers.  It
> > will
> > >> be
> > >> > ok  if  13  stands for  _13  and we'll all be happy.
> > >> >
> > >> > I'm sure that much of the world deals well without  imaginary
> numbers.
> > >> > However, they must have been a mess to develop so they work
> > flawlessly.
> > >> > Note that they do have a strange appearance but if you understand
> them
> > >> you
> > >> > get used to them.
> > >> >
> > >> > In my world, if I want  _8  I write  _1 0 0 0  which  is  in  the  8
> > 4 2
> > >> 1
> > >> > 8's digit.   So what is  _14 ?
> > >>  >
> > >> > Linda
> > >>
> > >> IN YOUR WORLD _14 IS
> > >>
> > >>     - 1 1 1 0
> > >>  _1 _1 _1 0
> > >>
> > >> AND IN TWO'S-COMPLEMENT IT IS
> > >>
> > >>     tcng 0 1 1 1 0
> > >>  1 0 0 1 0
> > >>
> > >>  ------------------
> > >>
> > >>  stack =: ,.&.|:  NB. stack x over y
> > >>
> > >>  hv =: (0 {:: <"1) :: ]  NB. return head vector
> > >>
> > >>   Tbln =: 2 2 2 $ 0 0,1 1,1 1,0 1  NB. table for tcng, see opn
> > >>
> > >>  ban =: 0 ,~ 0 ,.~ 0 ,.~ ]  NB. build argument, see tcng
> > >>
> > >>  opn =: ] stack~ (0 { [) , Tbln {~ [: < (0 { [) ,~ 2 { [: hv ]
> > >>
> > >>  tcng =: (1 {"1 [: }: [: opn/ ban)"1  NB. TWO'S-COMPLEMENT NEGATIVE
> > >>
> > >> ----------------------------------------------------------------------
> > >> For information about J forums see
> http://www.jsoftware.com/forums.htm
> > >>
> > >
> > >
> > >
> > > --
> > > Devon McCormick, CFA
> > > ^me^ at acm.
> > > org is my
> > > preferred e-mail
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to