Re: [Jprogramming] Matrix Transformations based on local submatrices

2012-11-17 Thread Raul Miller
On Fri, Nov 16, 2012 at 11:13 PM, Alex Giannakopoulos
aeg...@blueyonder.co.uk wrote:
 However, my concern was not the saving of 1k mem, but a deeper elegance
 issue.  I may be wrong here, I don't know, but I always prefer my data to
 exist as only one copy, and as many references to it as are needed.

Ok, but what is a reference?

From a garbage collection perspective, J's data structures form a
directed acyclic graph, but the language has no problems representing
cyclic graphs.  The reason for this is that data represents things for
us.

Numbers can be thought of as references.  For example, that's what
array indices are about, but I can think of a variety of other ways
that data can be references.

So what does it mean -- when our data is references -- to have only
one copy of the data and as many references to it as needed?

Personally, I tend to favor concepts of code simplicity and data integrity.

But this is a very general topic.

-- 
Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Arc consistency in J

2012-11-17 Thread Linda Alvord
Hi Michal,  I keep working on your code and I hit a snag?  Maybe someone can 
explain the domain error that I encounter.

   n=: 5 
   X=:(?(2#n)$2)*(i.n)/i.n
   adj=: 13 :'(0y)([:#)1 i.#y'
   A=:adj X
   
I'm trying to simplify  arcsX

   arcsX =: [: ( @ (,./)) ([ (,..)0 {)
   ](i.n) arcsX A
0 4
1 4
2 4
   
   h=:[: (G=:[:,./),..
   h
[: ([:  ,./) ,..
   ((i.n) arcsX A)-:(i.n) h A
1

And h works OK.   
   G
[:  ,./
   I=:,.0 2 
   I
,.0 2 
   ((i.n)G A)-:(i.n)I A
1

Then I found  I  to replace  G
   
   j=:[:(I=:,.0 2 ) ,..
   (i.n) h A
0 4
1 4
2 4
   (i.n) j A
|domain error: j
|   (i.n)j A

It doesn't work when inserted in  h

Linda

-
Original Message-
From: programming-boun...@forums.jsoftware.com 
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Michal D.
Sent: Friday, November 16, 2012 9:44 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Arc consistency in J

Boss is Boss, I eventually arrived at the same (non-negative case) solution.

Thanks km for the explanation of @ vs @: which I'm starting to slowly get.

Linda: I think I prefer having it on three lines.  It better breaks down the 
steps I'm trying to accomplish.  Maybe someday I'll be able to boil it down to 
a single line ;-)

Raul: please let me know if we should still pursue your previous definition in 
light of Mike's commentary.

Mike Day is right on with all his observations about what I'm trying to 
accomplish.  Sorry for the long delay - I'm having trouble keeping up.
Notes:

(0) Interesting {:: vs { and 

(1) The J arc consistency algorithm I've presented is not AC-3 nor any of the 
later AC algorithms.  AC-3 is simply another algorithm that accomplishes the 
same thing.

(2) Using the approach I do with the C-tables allows massive parallelism.
In particular using mostly logical-and and logical-or operations on boolean 
arrays allows a single assembly level operation to have 32 or 64 way 
parallelism (or larger if using vector registers).

(3) A simpler algorithm that requires a single version of each C-table and a 
revDom that reduces both it's input domains is possible but I haven't gotten 
there yet.  I'm working on it along with code to randomly generate a sudoku and 
generate the equivalent CSP.  It might be a while.

Cheers,

Mike


On Wed, Nov 14, 2012 at 3:11 PM, Mike Day mike_liz@tiscali.co.ukwrote:

 Thanks,  but my questions were rhetorical!  I was merely trying to 
 comment on Linda's apparent aversion to @ and @: and her preference 
 for [: which she has justified in a later post.  I'm not the Mike who 
 started this thread on arc consistency.

 Incidentally,  I also commented in that message on 11/11 (still in the 
 history below) about Raul Miller's question concerning the domain matrix D.

 Mike


 On 14/11/2012 11:24 AM, Linda Alvord wrote:

 Kip's comments are helpful.

 Back to your problem, Mike:

 X=:?(2#n)$2  NB. generate random matrix of [0,1]
 X=:X*(i.n)/i.n  NB. make it upper diagonal, zeros on diagonal
 ]X=:X+|:2*X
 0 0 0 0 1
 0 0 1 0 0
 0 2 0 0 0
 0 0 0 0 1
 2 0 0 2 0

 The three lines can be combined in one line.

 ]X+|:2*X=:(?(2#n)$2)*(i.n)/i.**n
 0 1 1 0 1
 2 0 1 0 1
 2 2 0 1 0
 0 0 2 0 0
 2 2 0 0 0

 Linda


 -Original Message-
 From: 
 programming-bounces@forums.**jsoftware.comprogramming-boun...@forums.jsoftware.com[mailto:
 programming-bounces@**forums.jsoftware.comprogramming-bounces@forums
 .jsoftware.com]
 On Behalf Of km
 Sent: Wednesday, November 14, 2012 4:29 AM
 To: programm...@jsoftware.com
 Subject: Re: [Jprogramming] Arc consistency in J

 Responding to Mike's query about @

 Mathematical composition  f o g  means do g first, then f and is 
 expressed in J by the monadic use of  f @: g  or  [: f g .  The 
 monadic use of  f @ g  can surprise you, compare

 |.@:+: 1 2 3
 6 4 2
 |.@+: 1 2 3
 2 4 6

 -- the first means double vector 1 2 3 then reverse the resulting 
 vector, the second means double and reverse each scalar then assemble the 
 results.

 Kip Murray

 Sent from my iPad


 On Nov 13, 2012, at 8:44 PM, Linda Alvord lindaalv...@verizon.net
 wrote:

  I can only give a personal response.  Maybe it is because I'm left
 handed.

 When I look at  ((@#)(i.n))@(0)  at or

 -Original Message-
 From: 
 programming-bounces@forums.**jsoftware.comprogramming-bounces@forum
 s.jsoftware.com 
 [mailto:programming-bounces@**forums.jsoftware.comprogramming-bounc
 e...@forums.jsoftware.com]
 On Behalf Of Mike
 Day
 Sent: Monday, November 12, 2012 6:40 AM
 To: programm...@jsoftware.com
 Subject: Re: [Jprogramming] Arc consistency in J

 But what's wrong with @ that's preferable with [:   ?(I think
 Th is has been asked before.)

 Aren't they both devices to represent what ordinary mathematicians
 just write as f g h ... for the composition of f g h ...   ?

 Since J cleverly allows hooks and forks and interprets unbracketed 
 trains of verbs as such,  it needs some other way to recognise 
 composition,  and