function F = BR_sentence2formula(s,p)
% BR_sentence2formula - convert logical sentence to nonlinear equation
% On input:
%     s (1xk vector): disjunctive clause
%     p (float): probability s
% On output:
%     F (string): equation for s with probability p
% Call:
%     Fs = BR_sentence2formula([-1,2],0.7);
% Author:
%     T. Henderson
%     UU
%     Spring 2017
%

len_s = length(s);
F = ['-',num2str(p),'+'];

for k = 1:len_s
    combos = nchoosek([1:len_s],k);
    num_combos = length(combos(:,1));
    if rem(k,2)==0
        c_sign = '-';
    else
        c_sign = '+';
    end
    for c = 1:num_combos
        if ~(c==1&k==1)
            F = [F,c_sign];
        end
        for m = 1:k
            atom = s(abs(combos(c,m)));
            if atom>0
                term = ['x(',int2str(abs(atom)),')'];
            else
                term = ['(1-x(',int2str(abs(atom)),'))'];
            end
            F = [F,term];
            if m<k
                F = [F,'*'];
            end
        end
    end
end
tch = 0;
