In
   A=. 0= ? (2$n)$2       NB. generate random matrix of [0,1]

The 0= is unnecessary, and probably reflects a habit based on the
false idea that boolean algebra is does not have an integer domain.
Boolean rings have (subset of) integer domains, and [even after
redefinition] boolean algebra is a boolean ring.

If you ever want to treat Heyting Algebras or Bayesian Probability you
might also want to consider what happens when you replace the $2 with
$0.

I think I would also be more comfortable with
   2 2 $ ''; 'y'; 'x'; A
for the displayed table, but that's a minor quibble.

An alternative definition for adj might be
   adj=: <@I.@:*

But somewhere around here, I get lost.  Your use pattern for arcsX is:

   (i.n) arcsX A

where A has the shape n,n

What is the domain of the left argument of arcsX?  I am guessing that
it's either i.n or a single element choosen from i.n but if that is
the case, I think I'd define arcsX to only work for the i.n case --
the name says "arcs" after all.  Also, if I wanted to extract the
values from the result of arcsX which correspond to a single value
from i. n, that's simple enough -- I can select on the first column of
the result.

In other words, perhaps something like this:

   arcs=: $ #: I.@,
   arcs *A

Also, I have not taken the time yet, to read "revise", so I will stop here.

-- 
Raul

On Sun, Nov 4, 2012 at 12:31 AM, Michal D. <[email protected]> wrote:
> Thank you everyone for the comments and encouragement.
>
> I think Bo's (?]) and accompanying code was an interesting illustration of
> a nice use of the hook.  I'm not sure why to prefer doubling an entire
> array as opposed to dividing a single scalar?  I think that inlining getx
> and gety is anti-style ;-).  See also all the argument unwrapping that
> happens in the new revise.  Too bad there is no way to prevent this.
>
> I take it that picking # over $ is a purely stylistic preference.  I
> appreciate all the comments regarding coppula and NB.*, both sound like a
> good idea.
>
> The historical comments regarding a hook conjunction exactly mirror my
> frustrations.  Thank you Raul also for arcsX2, that is a thing of beauty =).
>
> New and improved code at http://pastebin.com/fzs0GAev with an expanded
> intro to "CSPs".
>
> Cheers,
>
> Mike
>
> On Thu, Nov 1, 2012 at 10:01 PM, Michal D. <[email protected]>wrote:
>
>> Hi All,
>>
>> I've managed to write my first not-completely-trivial program in J.  It
>> implements an arc consistency algorithm (
>> http://en.wikipedia.org/wiki/Local_consistency#Arc_consistency).  I would
>> appreciate any comments regarding style, what I'm doing wrong in J or how
>> to improve the code.  I also have a couple of questions of my own:
>>
>> 1) how do I avoid @ especially once we remove explicit arguments?
>> 2) how do I avoid constant boxing/unboxing due to fill (see arcsX)?
>> 3) Is a boxed value always a pointer? One could imagine implementing
>> 'ragged' arrays without pointers.
>> 4) Is there a good way to have named variables (ie. avoid getx, gety)?
>> 5) Why is a hook the default and not composition?
>>
>> Code at: http://pastebin.com/k4XuKfFi
>>
>> Cheers!
>>
>> Mike
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to