Your approach is exactly what my f does!
That said, there's other ways of phrasing this. Also, for this
specific calculation, it would be easier to work with a representation
of the form
V1=: |:|.@> v1
V2=: |:|.@> v2
Then:
V2-:(~.@{.,:+&.>//./)V1
1
It may help to use the dissect utility documented at
https://code.jsoftware.com/wiki/Vocabulary/Dissect or to inspect the
results of sub-expressions.
(Mostly, when working with J -- and, for that matter, other languages
-- I find it pays to focus on how the data looks as it's being
transformed instead of trying to focus on the code itself. The code is
obvious and in front of you, but the intermediate results are harder
to see...)
Thanks,
--
Raul
On Mon, Nov 25, 2019 at 12:24 PM Arnab Chakraborty <[email protected]> wrote:
>
> Thanks, Raul. You are always so prompt with your help! I am yet to decipher
> your solution, but your suggestion regarding 2 column table is bang on
> point.
>
> My own approach was something like this: find nub of the 2nd column, then
> for each element in the nub collect all occurences of it, and sum over the
> coeffns.
>
> On Mon, 25 Nov 2019, 21:56 Raul Miller, <[email protected]> wrote:
>
> > Yes, definitely.
> >
> > For example, consider:
> >
> > <"1 ({:"1 (+&.>/@:({."1), (<0 1){])/. ])>v1
> >
> > Or,
> >
> > f=: 13 :'<"1 ({:"1 (+&.>/@:({."1), (<0 1){])/. ])>y'
> > f v1
> >
> > That said, this example may fall apart for your general case? (I don't
> > know what that is...)
> >
> > Specifically, I don't know why the top level structure of v1 and v2
> > would be a list of boxed entities if they are always pairs. It seems
> > to me that a table of two columns would be a more natural expression
> > of that, if that's the case.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> > On Mon, Nov 25, 2019 at 11:12 AM Arnab Chakraborty <[email protected]>
> > wrote:
> > >
> > > Dear all,
> > >
> > > I am trying to implement a geometric algebra system in J. I have done
> > > much of the stuff, but is getting stuck at one point. Hence this email.
> > >
> > > Basically, I have a list of boxes like
> > >
> > > v1=: (<2.3; 2 3 4), (<3.9; 1 2), <3.1; 2 3 4
> > >
> > > This represents a (multi)vector whose math representation is
> > >
> > > 2.3 * e_{234} + 3.9 * e_{12} + 3.1 * e_{234}.
> > >
> > > Here the e_{...}'s are some basis vectors. As you can see, e_{234} occurs
> > > twice in the list, and so this vector may be reduced to
> > >
> > > 5.4 * e_{234} + 3.9 * e_{12}.
> > >
> > > In J this should be
> > >
> > > v2=:(<5.4; 2 3 4), <3.9; 1 2
> > >
> > > I want to write a monad f such that f v1 is v2.
> > >
> > > Any idea?
> > >
> > > Thanks and regards.
> > >
> > > Arnab.
> > > ----------------------------------------------------------------------
> > > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm