function lam_msg = compute_lambda_msg_tabular(bnode, bnet, p)

% Pearl p183 eq 4.52

pearl = bnet.pearl;

n = bnode.self;

if pearl.maximize
  T0 = mk_max_table_from_bnode(bnode);
else
  T0 = mk_table_from_bnode(bnode);
end

self_size = bnode.sizes(end);
my_lambda = mk_table(n, self_size);
my_lambda.T = pearl.msg{n}.lambda;
T0 = multiply_by_potential(T0, my_lambda);

T1 = prod_pi_msgs_tabular(bnet, n, p);
T = multiply_by_potential(T0, T1);
lambda = marginalize_potential(T, p);
lam_msg = lambda.T;
