I would suggest a few amendments to your idea(s). 1. Consider the vector space of 1-cells over the integers, ie. of finite arrays of integer atoms. Multiplication by a scalar is as defined by J, adding is done by ([: +/ ,:)&.|. so the shorter vector is preceded by zeroes. Notice that a b c -: 0 a b c
2. A projection (with base x) from this vector space to the integers is done by pr=: ((^ i.@#) +/@:(*|.) ] ) It's rather obvious that this projection is linear, so its kernel K (all the 1-cells projected on 0) is a subspace. However, notice that this projection is not injective, but it is surjective, ie. every integer is the projection of some 1-cells. 3. If we want an inverse for this projection, we should choose a representative from y + K for each integer z = x pr y (with 1-cells x and y). For 0 <: z this is usual done by choosing r from y + K such that (0<: r) *./@: *. r < x 4. The solution Bron gave seems quite appropriate to choose a representative for the negative integers: For z < 0 and z = x pr y (with 1-cells x and y), choose r from y + K such that (r < 0) *./@: *. r (>-) x 5. It's obvious that for the projection one could use #. So for the inverse #.^:_1 should be appropriate. However, it does not work for negative z : 10(#.^:_1)_6543 3 4 5 7 so it should be adjusted to -@(pv-)`pv @.(0<:*) with pv=: #.^:_1 10 -@(pv-)`pv @.(0<:*) _6543 _6 _5 _4 _3 R.E. Boss > -----Oorspronkelijk bericht----- > Van: programming-boun...@jsoftware.com [mailto:programming- > boun...@jsoftware.com] Namens Marshall Lochbaum > Verzonden: donderdag 15 december 2011 3:38 > Aan: Programming forum > Onderwerp: Re: [Jprogramming] How #: should have been designed > > 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 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm