Focus on what you want to DO. You want to do "the square root of the mean of the square".
A novice's tip for using [: is to read [: f g as "the f of the g" . What you want is [: %: ( [: (+/%#) *: ) which you read as "the square root of ( the mean of the square )" . (Omitted one "the".) Because of J's right-to-left processing you can omit the outer parentheses and still read [: %: [: (+/%#) *: as "the square root of the mean of the square". Thus you can use rms =: [: %: [: (+/%#) *: Another tip is to read @: as "after". You want to do square root after doing mean after doing square. Thus rms =: %: @: (+/%#) @: *: also works. Pick what you are comfortable with and remember focus on what is to be DONE. J's verbs are DOERS. -- Kip Murray Sent from my iPad > On Nov 16, 2013, at 7:20 PM, Don Kelly <[email protected]> wrote: > > This is a novice problem (which arose from reading "Easy J" by Linda Alvort > I think that I have it worked out but this is something (IMHO) that possibly > should be in a primer. > I have occasion to use what is called rms or root mean square (usually > applied to a wave form). > I can define root, mean and square and can do something like: > root mean square 1 2 1 2 > or > %:(+/%#)*: 1 2 1 2 NB. in immediate > execution > 1.58114 OK > > A natural tendency equivalent to saying mean=: +/%# > is to try > rms=: %:(+/%#)*: > But rms 1 2 1 2 fails. > However rms=: 3: ' %:(+/%#)*:y' or rms=: 13: ' %:(+/%#)*:y' > is OK > and the latter is equivalent to > rms=:[:%:[:(+/%#)*: which works > > Alternatively rms=:%:@:(+/%#)@:*: also workS > > It is obvious that either the capped fork (from use of 13: or use of @: work > and I see > the reasoning behind this- forcing a sequential " root after mean after > square". > > Am I right in assuming that immediate execution of > %:(+/%#)*: y where y is explicitly entered > is treated as 3: or 13: ' %:(+/%#)*::y ' (explicitly in that the *:y is > the argument for mean(+/%#) whose value is the argument for %: i.e. as in APL > for which 'tacit' doesn't exist) > and rms=: %:(+/%#)*: as a tacit verb with no argument is parsed as a fork > rather than sequentially as desired and runs into never never land? > > The classic example of 'mean=:+/%# as a verb is misleading in that the > example is a single fork, but trying to extend it > does need a flag as to the need to emphasize the parsing. > (+/%#) *: 1 2 1 2 works but msg =:(+/%#)*: doesn't work but msg=:(+/%#)@:*: > or msg=:[:(+/%#)*: do work > > > Don Kelly > > -- > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
