I can't seem to stop myself from answering "style"questions:

I learned APL from Ken and was greatly influenced his notion of notation as
a tool of thght. To me he was a mathematician first. So  look at the start
of Taylor Coefficients as influenced by some of Raul's rules:

   X=:10%~I=:i.8
   I
0 1 2 3 4 5 6 7
   X
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
   F=: 1 2 1&p. 
   F
1 2 1&p.
   5!:4 <'F'
      ┌─ 1 2 1
── & ─┴─ p.   
   F 5
36
   F X
1 1.21 1.44 1.69 1.96 2.25 2.56 2.89
   
NB. c p. x  ↔  +/c*x^i.#c from vocabulary
   
   PD=: 13 :'+/x*y^i.#x'   NB.  p.  or p dot   
   PD
[: +/ [ * ] ^ [: i. [: # [
   
   5!:4 <'PD'
  ┌─ [:                   
  ├─ / ─── +              
  │                       
──┤     ┌─ [              
  │     ├─ *              
  └─────┤   ┌─ ]          
        │   ├─ ^          
        └───┤   ┌─ [:  y   
            │   ├─ i.     
            └───┤    ┌─ [:
                └────┼─ # 
                     └─ [ 

Build PD by:  tally  x , integers of tally  x, y to power of integers of
tally  x  and so forth ending with the sum of everything. As you build,
some of the “trimmings” are being handled for you. Forks and hooks are
inserted.
   
   PD 5
5
   |length error: PD
|   1 2 1     PD X

So, back to the drawing board:

#1 2 1 
3
   i.#1 2 1 
0 1 2
   X^/ i.#1 2 1 
1   0    0
1 0.1 0.01
1 0.2 0.04
1 0.3 0.09
1 0.4 0.16
1 0.5 0.25
1 0.6 0.36
1 0.7 0.49
   (+/"1) 1 2 1*"1 X^/i.#1 2 1  
1 1.21 1.44 1.69 1.96 2.25 2.56 2.89
   PD=: 13 :'+/"1 x*"1 y^/i.#x'
   PD
[: +/"1 [ *"1 ] ^/ [: i. [: # [
   5!:4 <'PD'
  ┌─ [:                       
  │     ┌─ / ─── +            
  ├─ " ─┴─ 1                  
  │                           
──┤     ┌─ [                  
  │     │     ┌─ *            
  │     ├─ " ─┴─ 1            
  │     │                     
  └─────┤     ┌─ ]            
        │     ├─ / ─── ^      
        │     │               
        └─────┤     ┌─ [:     
              │     ├─ i.     
              └─────┤    ┌─ [:
                    └────┼─ # 
                         └─ [ 
   1 2 1 PD X
1 1.21 1.44 1.69 1.96 2.25 2.56 2.89

The story has a happy ending.

Linda

-----Original Message-----
From: programming-bounces@forums.jsoftware.commailto:programming-bo
un...@forums.jsoftware.com] On Behalf Of Raul Miller
Sent: Friday, November 02, 2012 1:04 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Arc consistency in J

On Fri, Nov 2, 2012 at 1:01 AM, Michal D. <michal.dobrog...@gmail.com>
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:

Personally, I use "mostly" coding guidelines.  I recognize that there will
need to be cases where I do not comply with my own guidelines, but I use
these guidelines when I have no reason to do something
different:

No space between name and copula.  This makes it easy to search for
assignments to a name.

Case of name represents type assigned to name.  NOUNS, verbs,
Adverbs/Conjunctions

Feel free to ignore these...

> 1) how do I avoid @ especially once we remove explicit arguments?

@ is function composition.  It looks ugly because J limits itself to ASCII
sequences for its language.  What we would ideally want is a character that
looks like a small circle (but elevated slightly, to avoid confusion with
the letter o)  But ASCII itself is ugly -- ASCII's value is not its beauty
but its ubiquity.  That said, here are some equivalent cases:

  f@g
  f@:g"g
  ([: f g)"g
  f&g@(]"g)
  f&:g@(]"g)

Depending on your context, you may be able to remove @(]"g) or "g and still
retain equivalence, and additional equivalences may also be valid.  For
example:

  f@g y
  f&g y
  f&> <&g y

> 2) how do I avoid constant boxing/unboxing due to fill (see arcsX)?

Here are some alternative arcsX definitions:
arcsX1=:   [: ; [ ,.&.> {
arcsX2=:   [  ((#~ #@>) ,. ;@]) {

> 3) Is a boxed value always a pointer? One could imagine implementing 
> 'ragged' arrays without pointers.

That is how they are currently implemented, yes.

> 4) Is there a good way to have named variables (ie. avoid getx, gety)?

Define "good"...

One option is to use explicit code -- the definition of "explicit code" is
essentially "named variables".

> 5) Why is a hook the default and not composition?

It's historical:

http://www.jsoftware.com/pipermail/general/2006-January/026271.html
http://www.jsoftware.com/pipermail/general/2006-January/026274.html

> Code at: http://pastebin.com/k4XuKfFi

I have not taken the time to fully digest what you are doing there, but
it's possible that by characterizing the data differently the expressions
could be made more direct.  I cannot guarantee this (because I have not
taken the time to understand the purpose of what you are doing), but that
has been my experience in many other contexts.

FYI,

--
Raul
----------------------------------------------------------------------
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