Andrew Nikitin wrote:
> 
> 
>> For those who want to train their tacit muscles, here's a challenge. 
> 
>> A Markov algorithm is a specialized term rewriter.  It accepts ...
> 
>  
> 
> I am not sure the problem can be handled by tacit expressions better than
> with explicit expressions.
> 
> Tacit way to implement 'while' is body^:predicate^:_
> 
> In J as it is there is no information flow between body and predicate, but
> for this problem there is a significant sharing of information. predicate
> is true when a non-terminal rule was applied and body is the application
> of this rule.
> 
>  
> 
> Also, I belive, if you are demanding "tacit" solution, you should also use
> only tacitly defined utilities. stringreplace (which seems to be the
> cornerstone of the algorithm) is not.
> 
>  
> 
> Anyway, here is my submission (sans parsing)
> 
>  
> 
> NB. This rules file is extracted from Wikipedia:
> NB. http://en.wikipedia.org/wiki/Markov_Algorithm
> R1=:i.0 3
> R1=:R1,'A';'apple';0
> R1=:R1,'B';'bag';0
> R1=:R1,'S';'shop';0
> R1=:R1,'T';'the';0
> R1=:R1,'the shop';'my brother';0
> R1=:R1,'a never used';'terminating rule';1
> 
> T1=:'I bought a B of As from T S.'
> 
>  
> 
> mapply=: 4 : 0
> ri=.0
> while. ri<#x do.
>   z=.y E.~ p=.>{.r=.ri{x
>   ri=.1+ri
>   if. +./z do.
>     y=.((> 1 { r) , (#p) }. ])&.((z i. 1)&|.) y
>     ri=._*>{:r
>   end.
> end.
> y
> )
> 
> [...]
> 

Slightly shorter/faster/neater:

mapply1=: 4 : 0
t=.ri=.0
while. (-.t) *. ri<#x do.
 'p s t'=.ri{x
  y=.(s , (#p) }. ])&.((z i. 1)&|.)^:(f=.+./z=.p E. y) y
  ri=.(-.f)*ri+1
end.
y
)

-- 
View this message in context: 
http://old.nabble.com/Tacit-exercise-tp26818596s24193p26821788.html
Sent from the J Programming mailing list archive at Nabble.com.

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

Reply via email to