The problem with this is that we would prefer not to use negative numbers in antibase, since they can violate uniqueness of base representation. There's really no solution to this--my recommendation is to just never feed negative numbers to #: . However, an option that minimizes negative numbers (and is very close to simply having two's complement base representation) is to make the first digit negative if the number is negative. Thus #: becomes base =. [: |."_1@:> |.@(#:`(_1,#:)@.(<&0))&.> Basically, use J's #: , and prepend a _1 if the input is negative. Then reverse, box, open everything for fill, and reverse again.
base i:5 _1 0 1 1 _1 1 0 0 0 _1 0 1 0 _1 1 0 0 0 _1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 #. base i:5 _5 _4 _3 _2 _1 0 1 2 3 4 5 Marshall On Mon, Dec 12, 2011 at 2:09 PM, Dan Bron <j...@bron.us> wrote: > Maybe we should explore a different track. Forget all about the history of > computing hardware, and the advantages of one representation over another > when designing circuits. In purely mathematical terms, what are the > decimal > digits of the base-10 number -123 ? > > Working backwards: > > _123 NB. begin > -123 NB. notation->operation > _1 * 123 NB. definition of - > _1 * (1 * 10^2) + (2 * 10^1) + ( 3 * 10^0) NB. positional number > notation > (_1 * 10^2) + (_2 * 10^1) + (_3 * 10^0) NB. distribution of * over + > _1 _2 _3 +/ . * 10^2 1 0 NB. array simplification > 10 #. _1 _2 _3 NB. definition of #. > > Thus, to satisfy the purposes of inversion, we should have: > [all examples from here on are purely theoretical, and the > results differ in the extant implementations of J]: > > 10 #.^:_1: _123 > _1 _2 _3 > > And, analogously in base 2: > > 2 #.^:_1: 2b_101 NB. 2b_101 is J's notation > for -101 in base 2 > _1 0 _1 > #: 2b_101 NB. #: <=> 2&#.^:_1: > _1 0 _1 > #: _5 NB. _5 <=> 2b_101 (numbers > are analytic) > _1 0 _1 > > QED.* > > -Dan > > * Backwards compatibility notwithstanding > > PS: What implications does this have for modulus, as in _10 | 123 ? > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm