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

Reply via email to