function h = CS_clause2hp(clause,n)
% CS_clause2hp - converts a KB clause to a hyperplane normal form
%                 set of coefficients
% On input:
%     clause (1xk vector): disjunction; pos is atom, neg is negated atom
%     n (int): number of atoms in KB
% On output:
%     h (1 by (n+1) vector): hyperplane coefficients:
%       c_1*x_1 + c_2*x_2 +...+ c_n*x_n + c_(n+1)
% Call:
%     h = CS_clause2hp([-1,2],2);
% Author:
%     T. Henderson
%     UU
%     Fall 2021
% 

OFFSET = 0.999;  % 0.999;

k = length(clause);
I = unique(abs(clause));
alpha = zeros(n,1);
for j = 1:k
    i_j = abs(clause(j));
    alpha(i_j) = sign(clause(j));
end
alpha = alpha/norm(alpha);
b_k = ones(k,1)/k;
d = OFFSET*norm(b_k);
p = zeros(n,1);
indexes = find(clause<0);
atoms = abs(clause(indexes));
p(atoms) = 1;
q = p + d*alpha;
c = -dot(alpha,q);
if abs(c)<0.1
    c = 0;
end
h = [alpha',c];
