Did you compare the tacit verbs of these two functions?

   f=: 13 :'(i.y)</i.y'
   f
i. </ i.
   
   5!:4 <'f'
  -- i.     
--+- / --- <
  L- i.     
            ^
   upperRightOnes=: 13 : '(</ ]) i. y'
   upperRightOnes
[: (</ ]) i.
   
   5!:4 <'upperRightOnes'
  -- [:          
  │    -- / --- <
--+----+- ]      
  L- i.    


In situations like this I guess timing would be the referee.

Linda

-----Original Message-----
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Peter B.
Kessler
Sent: Tuesday, November 06, 2012 2:26 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Arc consistency in J

Linda Alvord wrote:
> This sequence has a few problems:
> 
> A=. ? (2$n)$2          NB. generate random matrix of [0,1]
> A=. A *. (i.n) </ i.n  NB. make it upper diagonal, zeros on diagonal
> ] A=. A + |: 2*A       NB. make it symmetrix referencing transpose in C.
> 
> All the ideas you used are correct. Maybe something like this is simpler:
> 
>     f=: 13 :'(i.y)</i.y'
>    (f n)+|:2*f n=:4
> 0 1 1 1
> 2 0 1 1
> 2 2 0 1
> 2 2 2 0
> 
> Linda

I have no idea where this fits in the scheme of sudoku solvers, but the
repeated use of "i. y" in your definition of "f" seems awkward, and the
repeated use of "f n" in your last statement seems awkward.  An alternative
to duplicating an expression is to evaluate it once and use it as an
argument to a monadic fork or hook, since those implicitly reference their
right argument for both the left and right verbs.  So you could write

       NB. The hook references  i. y  twice.
       upperRightOnes=: 13 : '(</ ]) i. y'
       upperRightOnes 4
    0 1 1 1
    0 0 1 1
    0 0 0 1
    0 0 0 0

       NB. The outer fork references  upperRightOnes y  twice.
       upperRightOnesLowerLeftTwos=: 13 : '(] + ([: |: (2&*)))
upperRightOnes y'
       upperRightOnesLowerLeftTwos 4
    0 1 1 1
    2 0 1 1
    2 2 0 1
    2 2 2 0

I am a total novice at J, so you can ignore my observations on programming
style.

                        ... peter

P.S. I can't believe that I'm actually advocating the use of a monadic hook,
since they are among the things I find most confusing, because of their
asymmetry.  If you have trouble reading the hook, you can rewrite it as a
monadic fork

       upperRightOnesFork=: 13 : '([ </ ]) (i. y)'
       upperRightOnesFork 4
    0 1 1 1
    0 0 1 1
    0 0 0 1
    0 0 0 0

which seems sort of redundant with the definition of hook[1].  The use of
"[" instead of "]" for the left verb of the fork is due to Raul Miller[2],
and serves to remind us to think about what this verb would mean if used as
a dyad.

[1] http://www.jsoftware.com/help/dictionary/dictf.htm
[2] http://jsoftware.com/pipermail/programming/2012-August/028995.html
----------------------------------------------------------------------
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