//this funtion prints the minimal expression in the Pruduct of sums form for a given 4-vriable kmap //this program requires noof.sci function []=kmappos(k) n=4; k(:,:,2)=zeros(n,n); var=['A' 'B' 'C' 'D']; p1=['A + B' 'A + B''' 'A'' + B''' 'A'' + B']; p2=['C + D';'C + D''';'C'' + D''';'C'' + D']; cmn4=4; cmn2=2; temp=1; disp(k(:,:,1)); disp("is :"); disp(" ") //checking for 16 cells for i=1:n for j=1:n if(k(i,j)~=1) temp=0; break; end end end printf(' '); if(temp==1) printf("1"); abort; end for i=1:n for j=1:n if(k(i,j)~=0) temp=0; break; end end end printf(' '); if(temp==1) printf("0"); abort; end //checking for 8 cells cases z1=zeros(2,4); z2=zeros(4,2); temp1=['00' '01' '11' '10']; temp2=temp1'; for i=1:n if(i==4) t=1; else t=i+1; end z=[k(i,:,1);k(t,:,1)]; if(z==z1) printf('('); k(i,:,2)=[1 1 1 1]; k(t,:,2)=[1 1 1 1]; a=strsplit(temp2(i,1)); b=strsplit(temp2(t,1)); c=strcmp(a,b); for in=1:max(size(c)) if(c(in)==0 & a(in)=='0') printf(var(in)); break; else if(c(in)==0 & a(in)=='1') printf('%s''',var(in)); break; end end end printf(')'); end end for j=1:n if(j==4) t=1; else t=j+1; end z=[k(:,j,1) k(:,t,1)]; if(z==z2) printf('('); k(:,j,2)=[1;1;1;1]; k(:,t,2)=[1;1;1;1]; a=strsplit(temp1(1,j)); b=strsplit(temp1(1,t)); c=strcmp(a,b); for in=1:max(size(c)) if(c(in)==0 & a(in)=='0') printf(var(2+in)); break; else if(c(in)==0 & a(in)=='1') printf('%s''',var(2+in)); break; end end end printf(')') end end //checking for 4 cells cases z1=zeros(1,4); z2=zeros(4,1); z3=zeros(2,2); temp1=['00' '01' '11' '10']; temp2=temp1'; for t=1:n z=k(t,:,1); no=noof(k(t,:,2)); if(z==z1 & no