function diff_orthants=orthants(circuitsBperp,circuitsM)
%By inspection of Bperp, we can see that columns 5 and 6, and columns 7 and 8 are the same, respectively, and hence will always have the same sign.
%By inspection of M we can see that columns 5 and 9 have opposite signs.
%Then, we only consider the orthants with the above restrictions, and we check which of those orthants contain a circuit of Bperp.
%For those orthants whose support coincide with a the support of a sum of circuits of Bperp, we check if they contain a circuit of M.
%We only keep those whose support coincide with the support of a sum of circuits of M.
V1=circuitsBperp;
W1=circuitsM;
xx={};
kx=1;
for j1=-1:1
for j2=-1:1
for j3=-1:1
for j4=-1:1
for j5=-1:1
for j6=-1:1
for j7=-1:1
z=[j1,j2,j3,j4,j5,j5,j6,j6,-j5,j7];%signs of the orthant
vva=[];
for i=1:size(V1,1)%we check which circuits of Bperp are "contained" in this orthant
if length(setdiff(find(V1(i,:)),find(z)))==0 %we first check if the support of the circuit is contained
zz=sign(V1(i,:)).*z;
if prod(sign(zz)<=0)+prod(sign(zz)>=0)==0 %if the support if contained, we check if all the nonzero signs coincide, or all are different
vva=[vva,i]; %if there is one +1 and one -1 coordinate, we keep the index to discard
endif
else
vva=[vva,i];%as the support of the circuit was not contained we keep the index to discard
endif
endfor %i
vv=setdiff([1:size(V1,1)],vva); %we discard the indices, i.e. we keep the circuits that are contained with appropriate sign
if size(vv,2)>0 %we only consider this orthant if there is at least one circuit contained with appropriate sign
cc=sum(abs(V1(vv,:))); %the support of this vector is the union of the supports of the circuits contained
if size(setdiff(find(z),find(cc)),2)==0 %we only consider this orthant if the support coincides with the union of the supports of the circuits contained in it
vva2=[];
for j=1:size(W1,1)%we check which circuits of M are "contained" in this orthant
if length(setdiff(find(W1(j,:)),find(z)))==0 %we first check if the support of the circuit is contained
zz2=sign(W1(j,:)).*z;
if prod(sign(zz2)<=0)+prod(sign(zz2)>=0)==0 %if the support if contained, we check if all the nonzero signs coincide, or all are different
vva2=[vva2,j]; %if there is one +1 and one -1 coordinate, we keep the index to discard
endif
else
vva2=[vva2,j];%as the support of the circuit was not contained we keep the index to discard
endif
endfor %j
vv2=setdiff([1:size(W1,1)],vva2); %we discard the indices, i.e. we keep the circuits that are contained with appropriate sign
if size(vv2,2)>0 %we only consider this orthant if there is at least one circuit contained with appropriate sign
cc2=sum(abs(W1(vv2,:))); %the support of this vector is the union of the supports of the circuits contained
if size(setdiff(find(z),find(cc2)),2)==0 %we only consider this orthant if the support coincides with the union of the supports of the circuits contained in it
xx{kx,1}=z; %the orthant
xx{kx,2}=vv; %the circuits of Bperp contained
xx{kx,3}=vv2; %the circuits of M contained
kx=kx+1;
endif
endif
endif
endif
endfor %j7
endfor %j6
endfor %j5
endfor %j4
endfor %j3
endfor %j2
endfor %j1
diff_orthants={};
%we keep different orthants, with the first nonzero coordinate positive:
k=1;
for i=1:size(xx,1)
ww=find(xx{i,1});
if length(ww)!=0
if xx{i,1}(ww(1))>0
diff_orthants{k,1}=xx{i,1};
diff_orthants{k,2}=xx{i,2};
diff_orthants{k,3}=xx{i,3};
k=k+1;
end
end
end
%