-module(engine3). -compile([export_all]). events() -> [{m1, ok}, {m2, ok}]. p({m1, ok}) -> 0.2; p(A) when is_tuple(A) -> none. cp({m2, ok}, {m1, ok}) -> 0.8; cp(_, _) -> none. getp({A, B}) when is_tuple(A), is_tuple(B) -> case cp(A, B) of none -> Pba = cp(B, A), Pa = getp(A), Pb = getp(B), Pba * Pa / Pb; X -> X end; getp(A) when is_tuple(A) -> case p(A) of none -> lists:sum([ getp({A, B})*getp(B) || B <- events(), p(B) /= none, cp(A,B) /= none ]); X -> X end.