I am not completely sure I follow the math here, so I threw together a crude symbolic version (which builds expressions rather than computes results).
paren=: ('(', ], ')'"_)^:(1 ~: #@;:) ident=:2 :0 : if. n -: x do. y elseif. n -: y do. x elseif. 1 do. x u y end. ) zero=:2 :0 : if. n -: x do. n elseif. n -: y do. n elseif. 1 do. x u y end. ) rident=:2 :0 : if. n -: y do. x else. x u y end. ) add=: (paren@[, '+', ])&": ident 0 &.> sub=: (paren@[, '-', ])&": rident 0 &.> mul=: (paren@[, '*', ])&": ident 1 zero 0 &.> div=: (paren@[, '%', ])&": rident 1 &.> sqrt=: '%:'&,&":&.> deduce =: *`%/"2@(,:(%:@*-.))@((,:,1:)%+/@[) predict=: (deduce~-@>:)~ induce =: (,:0:)+[predict(-+/)~ deduce =: mul`div/"2@(,:(sqrt@mul 1&sub))@((,:,(<1)"_)div add/@[)&(add&0) predict=: (deduce~ 0&sub@(1&add))~ induce =: (,:(<0)"_)&(0&add)add[predict(sub add/)~ a =: 20 5 0 (I'm doing crude stuff like adding 0 to normalize argument formats, and using 0-x to represent negation.) Anyways, I'm still not completely comfortable with this representation. I think I am uncomfortable with the way that probabilities get mixed in with expected values, but I'm not completely sure. Mostly, I think it's that I do not have the time to really think this through. Still, maybe this is of use to someone else... -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm