Thanks, looks good. Nice to see reusable code like 'trivial' and interesting case-select code with an adverb selector like:
> reduceStep=: reduce0`reduce1`]@.(2<. {.@{.) NonTrivial Small step, RREF with less characters: RREF =: {.&>@ (reduceStep@}.&.>^:(1<#&>)^:a:@<@reduceStep)&.|. @ REF I agree with your final note. *./0={.y handles both i.0 and i.0 0 In Haskell you need the first pattern rowEchelonForm [] = [] to handle [] The final pattern rowEchelonForm zs@([]:_) = zs handles [[]] If you leave out the first pattern, you get with a stupid argument like [] > rowEchelonForm [] *** Exception: /rref.hs:(62,1)-(69,29): Non-exhaustive patterns in function rowEchelonForm On 22-04-12 20:16, Raul Miller wrote: > Here's an attempt at making this code more "J-ish". Mostly, I have > been assigning names to blocks (instead of allowing anonymous blocks). > > I need better names, though. ref0N is not a very evocative name. > > > trivial=: 0 *./ .= {. > NonTrivial=: ^:(0 = trivial) > > refN=: (], 0,. [:REF 1 1}. [ - {."1@[ */ ]) (%{.)@{. > ref00=: 0,. [:REF }."1 > ref0N=: [:REF (}.,~ {. + ({.@#~ 0 ~: {."1)) > ref0=: ref0N`ref00@.(trivial@:|:) > REF=: refN`ref0@.(0 = {.@{.)NonTrivial > > reduce0=: {."1,. [: reduceStep }."1 > reduce1=: {., 0 ,. }."1@}.@(- ({."1 */ {.)) > reduceStep=: reduce0`reduce1`]@.(2<. {.@{.) NonTrivial > > RREF =: ([:{.&> (reduceStep@}.&.>^:(1<#&>)^:a:@<@reduceStep))&.|. @ REF > > Note that I have eliminated the code corresponding to > > if. 0=#y do. i.0 0 return. end. > > since this case never happens -- it is handled by > > if. *./0={.y do. y return. end. > > FYI, > -- Met vriendelijke groet, @@i = Arie Groeneveld ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm