Hardly something to apologise about - I really appreciate your help!
"My best attempt for up and down tuples is to represent up tuples as
columns and down tuples as rows (and scalars as scalars)." (Marshall)
^Nice idea. I'll mull on it. My initial thought was to have ups just
like normal vectors and downs as a boxed vector with a "down" prefix, in
order to simulate SCMUTILS where up is just a normal vector, but keeping
the option to change it in the future as SCMUTILS has done.
Technically, then, up vectors could also (optionally) be boxed with an
"up" prefix.
'up'; 1 2 3 4
┌──┬───────┐
│up│1 2 3 4│
└──┴───────┘
However, the rows/columns appraoach may be neater, since it is closer to
the math (I think)
I wonder if it would be acceptable to start a thread called SICM, to
keep it all together and stop it from spilling over?
Thanks again to everyone.
On Fri, 2010-12-10 at 20:20 -0500, Marshall Lochbaum wrote:
> Sorry for all the emails--I think this is the last. The final version of
> tuple utils, complete with the rotation matrix example:
>
> dispu=:3 :0
> if. 0...@$y do. ":y
> elseif. 1=#y do. dispd {.y
> elseif. do. '()' surround ((, ','&,)/ dispd"_1 y) end.
> )
> dispd=:3 :0
> if. 0...@$y do. ":y
> elseif. 1=#y do. dispu {.y
> elseif. do. '[]' surround ((, ','&,)/ dispu"_1 y) end.
> )
>
> disptuple=:' ' -.~ dispd
>
> multiply=: 4 :0
> assert. 0 0-: 2| x ,&(#...@$) y
> if. 0 e. x ,&(#...@$) y do. x*y NB. scalar multiplication
> elseif. x (-:|.)&(2{.$) y NB. contraction
> do. x (+/^:2 @:(multiply"_2) 1 0&|:) y
> elseif. do. x multiply"_ _2 y NB. non-contraction
> end.
> )
>
> NB. *****Example*****
>
> disptuple rot=.(2 1 1 2$ 2 1 _1 2)
> [(2,1),(_1,2)]
> disptuple r=.rot (*...@[ * |@[ o. ]) th=.0.25p1 NB. 45 degree rotation
> matrix
> [(0.707107,0.707107),(_0.707107,0.707107)]
> disptuple v=.,:1 0 NB. unit vector in the x direction
> (1,0)
> disptuple r multiply v
> (0.707107,0.707107)
> disptuple r multiply r NB. two 45 degree rotations -> one 90 degree
> rotation
> [(2.22045e_16,1),(_1,2.22045e_16)]
>
>
> Marshall
>
> -----Original Message-----
> From: Marshall Lochbaum [mailto:[email protected]]
> Sent: Friday, December 10, 2010 7:57 PM
> To: 'Programming forum'
> Subject: RE: [Jprogramming] Verbs that take verbs as arguments (pt 2)
>
> Now I can present a rather nice tuple display that conforms with the
> standards in SICM:
>
> dispu=:3 :0
> if. 0...@$y do. ":y
> elseif. 1=#y do. dispd {.y
> elseif. do. '()' surround ((, ','&,)/ dispd"_1 y) end.
> )
> dispd=:3 :0
> if. 0...@$y do. ":y
> elseif. 1=#y do. dispu {.y
> elseif. do. '[]' surround ((, ','&,)/ dispu"_1 y) end.
> )
>
> disptuple=:dispd
>
> This gives:
>
> u=.,:1 2 3
> d=.,.1 2 3
> s=.2
> disptuple@> u;d;s
> (1,2,3)
> [1,2,3]
> 2
> disptuple u multiply u
> ((1,2,3),(2,4,6),(3,6,9))
>
> You can also try
> disptu...@multiply&.>/~ u;d;s
> but I would rather not post boxes in an email.
>
> Marshall
>
>
> -----Original Message-----
> From: Marshall Lochbaum [mailto:[email protected]]
> Sent: Friday, December 10, 2010 7:33 PM
> To: 'Programming forum'
> Subject: RE: [Jprogramming] Verbs that take verbs as arguments (pt 2)
>
> A fully recursive version is given below:
>
> multiply=:4 :0 "2
> assert. 0 0-: 2| x ,&(#...@$) y
> if. 0 e. x ,&(#...@$) y do. x*y
> elseif. x ~:&(1 i. $) y do. x (+/@,@:(multiply"_2) |:) y elseif. do. x
> multiply"_2 _ y end.
> )
>
> Marshall
>
> -----Original Message-----
> From: Marshall Lochbaum [mailto:[email protected]]
> Sent: Friday, December 10, 2010 7:29 PM
> To: 'Programming forum'
> Subject: RE: [Jprogramming] Verbs that take verbs as arguments (pt 2)
>
> My best attempt for up and down tuples is to represent up tuples as columns
> and down tuples as rows (and scalars as scalars).
> Thus an up tuple has shape (1 n) and a down tuple has shape (n 1) .
> This gives, with many conditionals, a multiplication routine:
>
> multiply=:4 :0 "2
> assert. 0 0-: 2| x ,&(#...@$) y NB. reject odd
> ranks--these cannot be tuples
> if. 0 e. x ,&(#...@$) y do. x*y NB. one of x or y is a
> scalar
> elseif. x ~:&(1 i. $) y do. x (+/@,@:* |:) y NB. up*down or down*up
> elseif. do. x */ y end. NB. up*up or down*down
> )
>
> Which gives all the correct results--try
>
> u=. ,: 1 2 3
> d=. ,. 1 2 3
> s=. 2
> multiply&.>/ u;d;s
>
> One note is that this definition does not employ recursion as specified--it
> cannot handle nested tuples.
>
> Marshall
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Alex Gian
> Sent: Friday, December 10, 2010 6:55 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Verbs that take verbs as arguments (pt 2)
>
> Thanks very much for that Marshall and Raul,
>
> I will go over it in detail!
>
> BTW,
> If any Jers want to understand Wisdom & Sussman's approach to Classical
> Mechanics, using a clear unambiguous modern functional notation (=> computer
> executable) there is also a good introductory paper:
> "The Role of Programming in the formulation of Ideas"
> http://dspace.mit.edu/handle/1721.1/6707
>
> Also if you have got SICM, and want a brief intro into their model look at
> Chapter 8 (our notation) so that you don't have to glean the computational
> approach from reading the book.
> http://mitpress.mit.edu/sicm/book-Z-H-79.html#%_chap_8
>
> Finally, what I think will be an interesting J challenge (when I get round to
> it) is the implementation of their tuples. The text uses two types "up"
> and "down" tuples, with up tuples equivalent to regular vectors, while down
> tuples correspond to duals. There is an interesting contraction possible
> when tuples are of the same length and opposite type.
> You can get a taste of this from the MIT-scheme "scmutils" manual In the
> section on "Up tuples and Down tuples".
> http://groups.csail.mit.edu/mac/users/gjs/6946/refman.txt (about 10 screens
> down)
>
> My apologies for going a bit off-topic, but this stuff along with some
> practical applications will be my J playing field for the foreseeable...
>
>
>
>
> On Thu, 2010-12-09 at 22:57 -0500, Marshall Lochbaum wrote:
> > Having taken an incredibly shallow look at the first few pages of
> > SICM, I will now highly recommend to you the conjunction
> >
> > T=: 2 : '] , u d. (i.<:n)'
> >
> > where (u T n) gives the first n components of the "local tuple" of the
> > function u. It may then be applied to a time t to obtain the actual value
> > of this vector. So:
> >
> > *: T 4
> > ] , (*: , +: , 2"0)"0
> >
> > For the record, I am not entirely sure how this works with vector outputs
> > (or inputs, but these seem less important).
> >
> > Marshall
> >
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of Alex Gian
> > Sent: Thursday, December 09, 2010 7:53 PM
> > To: Programming forum
> > Subject: [Jprogramming] Verbs that take verbs as arguments (pt 2)
> >
> > Sorry to plague you with more newbie questions, but I'm a little pressed
> > for time here.
> >
> > OK, for anyone familiar with Scheme/Lisp/λ-calculus etc, here's what I'm
> > trying to do:
> >
> > (define (gamma q)
> > (lambda(t)
> > (list t (q t) ((d1 q) t)))
> >
> >
> > In other words, I want to pass a monadic verb (call it 'q') to the
> > 'gamma' verb/function and I want the result to be a monadic
> > verb/function that will accept a value ('t') and return a three elem
> > array of rank 1 t, q t, q D.1 t
> >
> > IOW, something like
> > testfunc =. gamma @ q
> > testfunc 1.1
> > 1.1 (q 1.1) ((q D.1) 1.1)
> >
> > (In case anyone wonders why the weird questions, I am working through
> > Sussman & Wisdom's SICM, and would like to try the code in parallel in
> > J to compare the two notations.)
> >
> > I suppose I am really trying to figure how J deals with anonymous
> > functions. Where I am getting stuck is the scoping of the values of y
> > (and x) in explicit definitions.
> >
> > I /could/ do it as a dyad, but
> > gamma=: dyad : 'y,(x y),x D.1 y'
> > doesn't seem to work for me either, and I really would prefer monadic,
> > kinda seeing how "currying" maps to J.
> >
> >
> >
> >
> >
> >
> > ----------------------------------------------------------------------
> > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm