In this I attempt to solve the alternation problem using ;: .  Upon
illegal characters or patterns the machine is supposed to write the word
with j=_1 , causing Index Error, trapped with  fsm :: _1:
I characterize my test data as "more" rather than "good".
My fsm indicates "Pass" when the problem occurs in the final pairs.
I've converted the data to ASCII to avoid core dump.
Hat's off for Raul's home-built fsm solving this problem.

I'm not pleased to present faulty code---
We've already discovered that
Engine: j701/2011-01-10/11:25
Library: 7.01.063
Platform: Linux 64
Installer: j701a_linux64.sh
implements dyadic sequential machine incorrectly.
Maybe the error lies elsewhere?


Note 0
   fsm 'bb'  NB. correct implementation raises Index Error
b
   (_1 -.@:-: fsm ::_1:)@> TD
1 1 1 0 1 1 1 0 1 0 1
1 1 1 0 1 1 1 0 1 0 1
   ,.TESTDATA
+---------------+
|0              |
|0              |
+---------------+
|0              |
|1              |
+---------------+
|1              |
|0              |
+---------------+
|1              |
|1              |
+---------------+
|1 0 0 1 0 1    |
|0 1 0 0 1 0    |
+---------------+
|0 1 0 1 0      |
|1 0 1 0 1      |
+---------------+
|0 0 1 0 0 0 0 1|
|1 0 0 0 1 0 0 0|
+---------------+
|1 0 0 0 1      |
|0 1 1 0 0      |
+---------------+
|1 0 0 1 0 1 1  |
|0 1 0 0 1 0 0  |
+---------------+
|0 1 0 0 1 0    |
|1 0 1 1 0 0    |
+---------------+
|1 1            |
|0 1            |
+---------------+
   TD
+-+-+-+-+------+-----+--------+-----+-------+------+--+
|a|b|c|d|cbacbc|bcbcb|bacabaac|cbbac|cbacbcc|bcbbca|cd|
+-+-+-+-+------+-----+--------+-----+-------+------+--+
|a|c|b|d|bcabcb|cbcbc|cabacaab|bccab|bcabcbb|cbccba|bd|
+-+-+-+-+------+-----+--------+-----+-------+------+--+
)


Note a:
  state   items
          00    01    10   other includes 1 1
0 start   0 1   1 1   2 1   3 3 
1 01      1 1   3 3   2 1   3 3 
2 10      2 1   1 1   3 3   3 3 
3 error   3 3   3 3   3 3   3 3 
)

FUNCTION=: 1

STATE=: (4 2 $ ".);._2 noun define
0 0   1 1   2 1   3 3   3 3 NB. use 8 entries per row
1 1   3 3   2 1   3 3   3 3
2 1   1 1   3 3   3 3   3 3
3 3   3 3   3 3   3 3   3 3
)

MAP=: 256 {.!.3 i.3  NB. {.!.3  sets the fill value as 3

NB. 2nd map provides 'abcx' for 0 0 , 0 1 , 1 0 , 1 1
MAP=: 0 1 2 0 1 2 (0 1 2 , a. i. 'abc')} 256#3

f=: ;&(|:@:,:)
TESTDATA=: (0 0 f 0 1),(1 0 f 1 1),(1 0 0 1 0 1 ,:0 1 0 0 1 0 );(0 1 0 1
0 ,:1 0 1 0 1 );(0 0 1 0 0 0 0 1,:1 0 0 0 1 0 0 0);(1 0 0 0 1 ,:0 1 1 0
0 );(1 0 0 1 0 1 1 ,:0 1 0 0 1 0 0 );(0 1 0 0 1 0 ,:1 0 1 1 0 0 );1,:0 1

TD=: (a. {~ (a.i.'a') + #.)@|:&.>@:(,: |.&.>) TESTDATA

fsm=: (FUNCTION;STATE;MAP)&;:
assert(2(#,:)1 1 1 0 1 1 1 0 0 0 0)-:(_1-.@:-:fsm ::_1:)@>TD




> Date: Mon, 30 Jul 2012 13:12:29 -0700
> From: "Peter B. Kessler" <[email protected]>
> To: [email protected]
> Subject: Re: [Jprogramming] Determining an 'alternating' binary array
> Message-ID: <[email protected]>
> 
> ...
> I see that J *has* a Sequential Machine (dyadic :;) operator.  Why
isn't that the right solution to the alternating 1's problem?


Linda Alvord's solution contain 0 1 1 0 and so probably worked as you
suggested.

> Conversely, why is it not J-like to filter out the 0 0 columns (and
check for 1 1 columns while you are there), then match successive 2x2
blocks to make sure they are all the same?  Either "2 2 $ 0 1 1 0" or "2
2 $ 1 0 0 1", whichever comes first?

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

Reply via email to