diff options
author | prashantsinalkar | 2020-04-14 10:19:27 +0530 |
---|---|---|
committer | prashantsinalkar | 2020-04-14 10:23:54 +0530 |
commit | 476705d693c7122d34f9b049fa79b935405c9b49 (patch) | |
tree | 2b1df110e24ff0174830d7f825f43ff1c134d1af /Switching_And_Finite_Automata_Theory_by_Z_Kohavi | |
parent | abb52650288b08a680335531742a7126ad0fb846 (diff) | |
download | all-scilab-tbc-books-ipynb-476705d693c7122d34f9b049fa79b935405c9b49.tar.gz all-scilab-tbc-books-ipynb-476705d693c7122d34f9b049fa79b935405c9b49.tar.bz2 all-scilab-tbc-books-ipynb-476705d693c7122d34f9b049fa79b935405c9b49.zip |
Initial commit
Diffstat (limited to 'Switching_And_Finite_Automata_Theory_by_Z_Kohavi')
14 files changed, 5584 insertions, 0 deletions
diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/1-Number_System_and_Codes.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/1-Number_System_and_Codes.ipynb new file mode 100644 index 0000000..92a4b90 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/1-Number_System_and_Codes.ipynb @@ -0,0 +1,508 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 1: Number System and Codes" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.10: Division_of_Two_Binary_Numbers.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"format('v',8);//changing the default precision to 8\n", +"a=1000100110;//first number \n", +"b=11001;//second number\n", +"A=bin21dec(a);//converting a in to decimal number \n", +"B=bin21dec(b);//converting b in to decimal number \n", +"S=A/B; //multiply the two decimal numbers\n", +"temp=dec21bin(S);//converting the decimal product back to binary\n", +"disp('quotient');\n", +"disp(temp);//displaying the final output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.1: converts_no_to_base_10.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc //clears the command window \n", +"clear//clears all the variables \n", +"\n", +"i=1;w=1;//flags\n", +"\n", +"bin=432.2//given octal number which should be expressed in base 10\n", +"temp1=floor(bin);//separating integer part from the given number\n", +"temp2=modulo(bin,1);//separating decimal part from the given number\n", +"temp2=temp2*10^3;//converting decimal value to interger for convenience\n", +"while(temp1>0)//storing each integer digit in vector for convenience\n", +" p(i)=modulo(temp1,10);\n", +" temp1=round(temp1/10);\n", +" i=i+1;\n", +"end\n", +"while(temp2>0)//storing each decimal digit in vector for convenience\n", +" q(w)=modulo(temp2,10);\n", +" temp2=(temp2/10);\n", +" temp2=round(temp2);\n", +" w=w+1;\n", +"end\n", +"temp1=0;//clearing temporary variable 'temp1'\n", +"for i=1:length(p)//checking whether it is a binary number or not\n", +" if(p(i)>8) then\n", +" disp('not a binary number');\n", +" abort; \n", +" end\n", +"end\n", +"\n", +"for i=1:length(p)//multipliying the bits of integer part with their position values and adding \n", +" temp1=temp1+(p(i)*8^(i-1));\n", +"end\n", +"\n", +"temp2=0;//flag bit\n", +"\n", +"for z=1:length(q)\n", +"//multipliying the bits of decimal part with their position values and adding \n", +" temp2=temp2+(q(z)*8^(-1*(4-z)));\n", +"end\n", +"temp=temp1+temp2;\n", +"//finally adding both the integer and decimal parts to get total output.\n", +"disp(temp);//displaying the output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.2: converts_binary_number_to_base_10.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;//clears the command window \n", +"clear;//clears all the variables \n", +"i=1;w=1;\n", +"bin=1101.01;//Given binary number which we need to be convert into decimal \n", +"temp1=floor(bin);//separating integer part from the given number\n", +"temp2=modulo(bin,1);//separating decimal part from the given number\n", +"temp2=temp2*10^3;//converting decimal value to interger for convenience\n", +"while(temp1>0)//storing each integer digit in vector for convenience\n", +" p(i)=modulo(temp1,10);\n", +" temp1=floor(temp1/10);\n", +" i=i+1;\n", +"end\n", +"while(temp2>0)//storing each decimal digit in vector for convenience\n", +" q(w)=modulo(temp2,2);\n", +" temp2=(temp2/10);\n", +" temp2=floor(temp2);\n", +" w=w+1;\n", +"end\n", +"temp1=0;//flag bit\n", +"for i=1:length(p)//checking whether it is a binary number or not\n", +" if(p(i)>1) then\n", +" disp('not a binary number');\n", +" abort; \n", +" end\n", +"end\n", +"for i=1:length(p)\n", +"//multipliying bits of integer part with their position values and adding \n", +" temp1=temp1+(p(i)*2^(i-1));\n", +"end\n", +"temp2=0;//flag bit\n", +"for z=1:length(q)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp2=temp2+(q(z)*2^(-1*(4-z)));\n", +"end\n", +"temp=temp1+temp2;\n", +"//finally adding both the integer and decimal parts to get total output.\n", +"disp(temp);//displaying the output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.3: convert_decimal_number_to_base_8.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;//clears the command window \n", +"clear;//clears all the variables \n", +"format('v',8);//making the default precision to 8 significant digits\n", +"i=1;\n", +"dec=548;//given decimal number which should be expressed in base 8\n", +"temp=dec;\n", +"i=1;\n", +"d=8;\n", +"while(temp>0)//storing each integer digit in vector for convenience\n", +" p(i)=(modulo(floor(temp),d))\n", +" temp=floor(temp)/d;\n", +" i=i+1;\n", +"end\n", +"temp2=0;\n", +"for j=1:length(p)\n", +"//multipliying bits of integer part with their position values and adding \n", +" temp2=temp2+(p(j)*10^(j-1));\n", +"end\n", +"disp(temp2,'Octal number');\n", +"dec=345;\n", +"//given decimal number which should be expressed in base 8\n", +"temp=dec;\n", +"i=1;\n", +"d=6;\n", +"while(temp>0)//storing each integer digit in vector for convenience\n", +" p(i)=(modulo(floor(temp),d))\n", +" temp=floor(temp)/d;\n", +" i=i+1;\n", +"end\n", +"temp2=0;\n", +"for j=1:length(p)\n", +"//multipliying bits of integer part with their position values and adding \n", +" temp2=temp2+(p(j)*10^(j-1));\n", +"end\n", +"disp(temp2,'Base 6');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.4: Convert_decimal_value_in_base_10_to_base_8.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;//clears the command window \n", +"clear;//clears all the variables \n", +"format('v',8);//making the default precision to 8 significant digits\n", +"i=1;\n", +"dec=0.3125;//given decimal number which should be expressed in base 8\n", +"temp=modulo(0.3125,1);//separating decimal part from the given number\n", +"\n", +"while(temp~=0) //storing each decimal digit in vector for convenience\n", +" temp=temp*8;\n", +" p(i)=floor(temp);\n", +" i=i+1;\n", +" temp=modulo(temp,1);\n", +"end \n", +"\n", +"temp1=0; //flag bit\n", +"for j=1:length(p)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp1=temp1+(10^(-1*j)*p(j))\n", +"end\n", +"disp(temp1);//displays the final output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.5: convert_decimal_number_to_base_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;//clears the command window \n", +"clear;//clears all the variables \n", +"format('v',18);//changing the default prcision to 20 significant digits\n", +"\n", +"i=1;x=1;//flag bits\n", +"\n", +"dec=432.354;//given decimal number which should be expressed in base 2\n", +"temp2=floor(dec);//separating integer part from the given number\n", +"temp4=modulo(dec,1);//separating decimal part from the given number\n", +"\n", +"while(temp2>0)//storing each integer digit in vector for convenience\n", +" p(i)=(modulo(floor(temp2),2))\n", +" temp2=floor(temp2)/2;\n", +" i=i+1;\n", +"end\n", +"\n", +"temp2=0;//clearing temporary variable 'temp2'\n", +"\n", +"for j=1:length(p)\n", +"//multipliying bits of integer part with their position values and adding \n", +" temp2=temp2+(p(j)*10^(j-1));\n", +"end\n", +"\n", +"while(temp4~=0) //storing each decimal digit in vector for convenience\n", +" temp4=temp4*2;\n", +" d(x)=floor(temp4);\n", +" x=x+1;\n", +" temp4=modulo(temp4,1);\n", +"end \n", +"\n", +"temp5=0; //clearing temporary variable 'temp5'\n", +"\n", +"for j=1:length(d)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp5=temp5+(10^(-1*j)*d(j))\n", +"end\n", +"\n", +"temp3=temp2+temp5;\n", +"//finally adding both the integer and decimal parts to get total output.\n", +"disp(temp3);//displays output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.6: Convert_Octal_number_to_Base_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;//clears the command window \n", +"clear;//clears all the variables \n", +"format('v',8);//setting the default precision to 8\n", +"\n", +"i=1;w=1;\n", +"\n", +"bin=123.4; //Given octal number which we need to be convert into binary\n", +"temp1=floor(bin);//separating integer part from the given number\n", +"temp2=modulo(bin,1);//separating decimal part from the given number\n", +"temp2=temp2*10^3;//converting decimal value to interger for convenience\n", +"\n", +"while(temp1>0) //storing each integer digit in vector for convenience\n", +" p(i)=modulo(temp1,10);\n", +" temp1=round(temp1/10);\n", +" i=i+1;\n", +"end\n", +"\n", +"while(temp2>0) //storing each decimal digit in vector for convenience\n", +" q(w)=modulo(temp2,10);\n", +" temp2=(temp2/10);\n", +" temp2=round(temp2);\n", +" w=w+1;\n", +"end\n", +"\n", +"temp1=0; //clearing temporary variable 'temp1'\n", +"\n", +"for i=1:length(p) //checking whether it is a binary number or not\n", +" if(p(i)>8) then\n", +" disp('not a binary number');\n", +" abort; \n", +" end\n", +"end\n", +"\n", +"for i=1:length(p)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp1=temp1+(p(i)*8^(i-1));\n", +"end\n", +"\n", +"temp2=0;//clearing temporary variable 'temp2'\n", +"\n", +"for z=1:length(q)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp2=temp2+(q(z)*8^(-1*(4-z)));\n", +"end\n", +"\n", +"temp=temp1+temp2;\n", +"//adding both integer and decimal parts to get total deciaml value.\n", +"dec=temp;\n", +"\n", +"temp2=floor(dec); //separating integer part from the given number\n", +"temp3=modulo(dec,1);//separating decimal part from the given number\n", +"format('v',18);//setting the default precision to 8\n", +"\n", +"i=1;x=1;//flag bits\n", +"\n", +"while(temp2>0)//storing each integer digit in vector for convenience\n", +" p(i)=(modulo(floor(temp2),2))\n", +" temp2=floor(temp2)/2;\n", +" i=i+1;\n", +"end\n", +"\n", +"temp2=0; //clears temporary variable 'temp2'\n", +"\n", +"for j=1:length(p)\n", +"//multipliying bits of integer part with their position values and adding \n", +" temp2=temp2+(p(j)*10^(j-1));\n", +"end\n", +"\n", +"temp4=modulo(temp3,1);\n", +"\n", +"while(temp4~=0)//storing each decimal digit in vector for convenience\n", +" temp4=temp4*2;\n", +" d(x)=floor(temp4);\n", +" x=x+1;\n", +" temp4=modulo(temp4,1);\n", +"end \n", +"\n", +"temp5=0; //clears temporary variable 'temp2'\n", +"\n", +"for j=1:length(d)\n", +"//multipliying bits of decimal part with their position values and adding \n", +" temp5=temp5+(10^(-1*j)*d(j))\n", +"end\n", +"\n", +"temp=temp2+temp5;\n", +"//finally adding both the integer and decimal parts to get total output.\n", +"disp(temp);//displaying the output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.7: Adds_two_binary_numbers.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"a=0111.10; //first number \n", +"b=1111.01; //second number\n", +"A=bin21dec(a); //converting a in to decimal number \n", +"B=bin21dec(b); //converting b in to decimal number \n", +"S=A+B; //adding the two decimal numbers\n", +"temp=dec21bin(S); //converting the decimal sum back to binary\n", +"format('v',10); //changing the default precision to 8\n", +"disp(temp); //displaying the final output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.8: Subtracts_Two_Binary_numbers.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"format('v',8); //changing the default precision to 8\n", +"a=10010.11; //first number \n", +"b=01100.10; //second number\n", +"A=bin21dec(a); //converting a in to decimal number \n", +"B=bin21dec(b); //converting b in to decimal number \n", +"S=A-B; //subtracting the two decimal numbers\n", +"temp=dec21bin(S); //converting the decimal number back to binary\n", +"disp(temp); //displaying the final output" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 1.9: Multiplies_two_Binary_numbers.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"format('v',8); //changing the default precision to 8\n", +"a=11001.1; //first number \n", +"b=110.1; //second number\n", +"A=bin21dec(a); //converting a in to decimal number \n", +"B=bin21dec(b); //converting b in to decimal number \n", +"S=A*B; //multiply the two decimal numbers\n", +"temp=dec21bin(S); //converting the decimal product back to binary\n", +"disp(temp); //displaying the final output" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/10-Capabilities_Minimization_and_transformation_Of_Sequential_Machines.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/10-Capabilities_Minimization_and_transformation_Of_Sequential_Machines.ipynb new file mode 100644 index 0000000..124e842 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/10-Capabilities_Minimization_and_transformation_Of_Sequential_Machines.ipynb @@ -0,0 +1,107 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 10: Capabilities Minimization and transformation Of Sequential Machines" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.1: Reducing_machine.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp(' ... NS ');\n", +"disp(' PS x=0 x=1 ');\n", +"disp(' A E,0 C,0 ');\n", +"disp(' B C,0 A,0 ');\n", +"disp(' C B,0 G,0 ');\n", +"disp(' D G,0 A,0 ');\n", +"disp(' E F,1 B,0 ');\n", +"disp(' F E,0 D,0 ');\n", +"disp(' G D,0 G,0 ');\n", +"disp('Initial partition consists of all the states');\n", +"disp('P0=(ABCDEFG)');\n", +"disp('Since E only has 1 equivalent different from others,it can be partitioned from others');\n", +"disp('P1=(ABCDFG)E');\n", +"disp('now check for 2-equivalent i.e. 1-equivalent and their Ii succesors for all possible Ii are also 1 equivalent');\n", +"disp('A,F dont satisfy the 2-equivalent so they can be partitioned from others');\n", +"disp('P2=(AF)(BCDG)E');\n", +"disp('In the similar manner P3 can be obtained by splitting BD and CG since they dont have the same 3 equivalent');\n", +"disp('P3=(AF)(BD)(CG)E');\n", +"disp('In the same way P4 can be obtained by splitting A and F');\n", +"disp('P4=(A)(F)(BD)(CG)E');\n", +"disp('P4 cant be splitted more so P5 will be the same and the partition stops');\n", +"disp('P5=(A)(F)(BD)(CG)(E)');\n", +"disp('so the reduced machine is');\n", +"disp(' ... NS ');\n", +"disp(' .. PS x=0 x=1 ');\n", +"disp(' A----a e,0 c,0 ');\n", +"disp(' F----f e,0 b,0 ');\n", +"disp(' .(BD)--b c,0 a,0 ');\n", +"disp(' (CG)--c b,0 c,0 ');\n", +"disp(' E----e f,1 b,0 ');\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.2: Compaitability_Graph.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Considering the merger graph of machine M6 in PG 339');\n", +"disp('A set of compaitabilities is said to be closed if and only if for every compaitable contained in the set and all its implied compaitabilities are also in the same set');\n", +"disp('A closed set of compaitables which contains all the states of M is called a closed covering');\n", +"disp('By observing the merger graph we can find that {(AD)(BE)(CD)} is a closed set ');\n", +"disp('And the set {(AB)(CD)(EF)} appears to be a closed covering');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/12-Structure_Of_Sequential_Machines.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/12-Structure_Of_Sequential_Machines.ipynb new file mode 100644 index 0000000..796d253 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/12-Structure_Of_Sequential_Machines.ipynb @@ -0,0 +1,317 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 12: Structure Of Sequential Machines" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.10: Autonous_Clock.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Partition pi of the machine M5 is {(AB),(CD),(EF)}');\n", +"disp('If M5 posses a closed partition pi such that pi>λi .if the autonomous clock has #pi states the period p will be less than or equal to #pi ');\n", +"disp('since in the above closed partition of M5 we have 3 states i.e. (AB) as one state and (CD) and (EF) as other two');\n", +"disp('So the periodof the autonomous clock is p=3')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.11: partition_pair.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear\n", +"disp('From the definition of partition pair(T,T^)which is an ordered pair of partitions such that if Si and Sj are in the same block of t, then for every input Ik in I, next states are in the same block of T^ ');\n", +"disp('By applying the above definition we can obtain the following partition pairs');\n", +"disp('(pi1,pi1^)=({(ABC),(DEF)},{(ABC),(DEF)})');\n", +"disp('(t1,t1^)=({(ABCD),(EF)},{(AE),(BCDF)})');\n", +"disp('(t2,t2^)=({(AE),(BCDF)},{(ACDE),(BF)})');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.12: partition_pair_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//1 is equivalent to A ad 2 to B and so on.\n", +"p1=['A' 'D']; //pairs in partition t(1 and 4 represents that 1st and 4th state are in the same block);\n", +"p2=['C' 'E'];\n", +"\n", +"q1=['A' 'E']; //pairs in partition t^\n", +"q2=['B' 'D'];\n", +"q3=['C' 'F'];\n", +"\n", +"disp('the following are the partitions of the machine M8');\n", +"disp('T');\n", +"disp('F',p2(2),p2(1),'B',p1);\n", +"disp('T^');\n", +"disp(q3,q2,q1);\n", +"disp('------');\n", +"disp('T');\n", +"disp('F',p2,'B',p1);\n", +"disp('T^');\n", +"disp(q3,[q1 q2]);\n", +"disp('------');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.14: State_Consistent_Partitions.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//assume the first cloumn values are of machine M1 and 2nd column are of M2\n", +"p=[1,1;1 3;2 2;2 4;3 3;3 1;4 4;4 2];\n", +"z=1;\n", +"for i=1:length(p(:,1))\n", +" for j=i:length(p(:,1))\n", +" if(p(i,1)==p(j,1) & i~=j)\n", +" q(z,:)=[p(i,:) p(j,:)];\n", +" z=z+1;\n", +" end\n", +" end\n", +"end\n", +"disp('pi(R)');\n", +"disp(q);\n", +"z=1;\n", +"for i=1:length(p(:,1))\n", +" for j=i:length(p(:,1))\n", +" if(p(i,2)==p(j,2) & i~=j)\n", +" q(z,:)=[p(i,:) p(j,:)];\n", +" z=z+1;\n", +" end\n", +" end\n", +"end\n", +"disp('pi(S)');\n", +"disp(q);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.4: Closed_Partitions.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('we know that a partition pi on the set of states of a Sequential machine M is said to be closed if,for every two states Si and Sj which are in the same block of pi and any Ith input successor of Si and Sj are also in the same group');\n", +"disp('Based on the above definition we can make seven closed partitions as below');\n", +"disp('**Parition 1**');\n", +"disp('{A,B,C,D,E,F,G,H}')\n", +"disp('**Parition 1**');\n", +"disp('{(ABCD)(EFGH)}');\n", +"disp('**Parition 2**');\n", +"disp('{(ADEH)(BCFG)}')\n", +"disp('**Parition 3**');\n", +"disp('{(AD)(BCFG)(EH)}');\n", +"disp('**Parition 4**');\n", +"disp('{(ADEH)(BC)(FG)}')\n", +"disp('**Parition 5**');\n", +"disp('{(AD)(BC)(EH)(FG)}')\n", +"disp('**Parition 6**');\n", +"disp('{(ABCCDEFGH)}');\n", +"disp('By assigning values from 000 to 111 to all the states from A to H and obtaining the functions for Y1,Y2,Y3 and z will result in this equations');\n", +"disp('Y1=x^y1^');\n", +"disp('Y2=x^y2+xy2^');\n", +"disp('Y3=xy2+x^y1^y2y3^+y3^y2^y3+y1y2y3+x^y1y2^y3^');\n", +"disp('z=y1^y2^y3');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.5: Output_Consistent.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('For the 4 state machine M4 in PG 397');\n", +"disp('IF the four states A,B,C,D are assigned as 00,01,10,11(ta={(AC)(BD)}) and 00,01,11,10(tb={(AD)(BC)})');\n", +"disp('And if the output,next state functions of both the assignments are calculated we can find that ');\n", +"disp('For first assignment ');\n", +"disp('Y1=x^y1+xy1^');\n", +"disp('Y2=x^y2^+y1^y2^+xy1y2');\n", +"disp('z=x^y1^y2^+x^y1y2+xy1^y2+xy1y2^');\n", +"disp('Second Assignment ');\n", +"disp('Y1=x^y1+x^y1');\n", +"disp('Y2=x^y2^+xy1^y2+y1y2^');\n", +"disp('z=x^y2^+xy2');\n", +"disp('Since the second assignment results in reduced output expression this partition is called as output-consistent partition')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.7: Dependence.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('A partition pi0 on the states of a machine M is said to be output consistent if for every block pi0 and every input,all the states contained in the block have the same outputs');\n", +"disp('Considering the above definition It can be understood that');\n", +"disp('pi0={(AD),(BC)} is an output consistent partition of machine M4');\n", +"disp('since the outputs of A,D states for any inputs are same and similarly the outputs of B,C are same.');\n", +"disp('So the partition {(AD),(BC)} are said to be output consistent');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.8: input_Consistent_Matrix.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('For the Machine M5 in PG 400');\n", +"disp('State A implies the identification of states C and D');\n", +"disp('similarly C implies the identification of E and F states');\n", +"disp('In the same way C implies the identification of A and B');\n", +"disp('Thus the smallest input consistent partition for M5 is ');\n", +"disp('pi={(AB),(CD),(EF)}');\n", +"disp('Any other partition that contains pi is also input consistent')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.9: Implementation_of_Input_Consistent_matrix.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('In previosuly problems we have determined the input and output consistent partitions for the Machine M5');\n", +"disp('Input consistent partition {(AB),(CD),(EF)}');\n", +"disp('Output consistent partition {(ACE),(BDF)}');\n", +"disp('By assigning 000 to 101 to all the states from A to F');\n", +"disp('we can find the expressions for the next state and the output');\n", +"disp('Y1=y2');\n", +"disp('Y2=y1^y2^');\n", +"disp('Y3=xy3+xy2+x^y2^y3^+y2y3');\n", +"disp('z=xy3^');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/13-State_Identificaiton_And_Fault_Detection_Experiments.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/13-State_Identificaiton_And_Fault_Detection_Experiments.ipynb new file mode 100644 index 0000000..5303cf5 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/13-State_Identificaiton_And_Fault_Detection_Experiments.ipynb @@ -0,0 +1,72 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 13: State Identificaiton And Fault Detection Experiments" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.1: Fault_DetectionExeriment.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('By following the general procedure for fault detection in the text book Page n.o 478');\n", +"disp('According to 3 & 4 steps of general procedure all the inputs are taken as 0 and the output is checked]');\n", +"disp('X: 0 0 0');\n", +"disp(' A B A B');\n", +"disp('Z: 1 0 1');\n", +"disp('By following the step 5');\n", +"disp('X: 1 0');\n", +"disp(' B B A');\n", +"disp('Z: 0 0');\n", +"disp('Accoring to step 6');\n", +"disp('X: 1 0 0 1 0 0');\n", +"disp(' A D D D C D D');\n", +"disp('Z: 0 3 3 1 2 3');\n", +"disp('Step 7 & 8')\n", +"disp('X: 1 1 0');\n", +"disp(' D C A B');\n", +"disp('Z: 1 1 1');\n", +"disp('Whole checking experiment')\n", +"disp('X: 0 0 0 1 0 1 0 0 1 0 0 1 1 0');\n", +"disp(' A B A B B A D D D C D D C A B');\n", +"disp('Z: 1 0 1 0 0 0 3 3 1 2 3 1 1 1');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/14-Memory_Definiteness_Information_Losslessness_of_Finite_Automata.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/14-Memory_Definiteness_Information_Losslessness_of_Finite_Automata.ipynb new file mode 100644 index 0000000..079bbf5 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/14-Memory_Definiteness_Information_Losslessness_of_Finite_Automata.ipynb @@ -0,0 +1,355 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 14: Memory Definiteness Information Losslessness of Finite Automata" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.2: Synchronizing_tree.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"N=4;\n", +"//state table of the machine\n", +"s=[ 'PS' 'x=0' 'x=1';\n", +" 'A' 'A' 'B';\n", +" 'B' 'C' 'B';\n", +" 'C' 'A' 'D';\n", +" 'D' 'C' 'B'];\n", +"k=1;l=2;m=1;n=1;\n", +"f(k,4)='ABCD';\n", +"k=k+1;\n", +"for i=2:max(size(s(:,1)))\n", +" for j=i:max(size(s(:,1)))\n", +" if(s(i,2)==s(j,2) & i~=j)\n", +" f(k,l)=strcat([s(i,1) s(j,1)]);\n", +" l=l+4;\n", +" if(s(i,2)==s(j,2))\n", +" g(n,m)=s(i,2);\n", +" g(n,m+1)='-';\n", +" m=m+2;\n", +" else\n", +" g(n,m)=s(i,2);\n", +" g(n,m+1)=s(j,2);\n", +" g(n,m+2)='-';\n", +" m=m+3;\n", +" end\n", +" if(s(i,3)==s(j,3))\n", +" g(n,m)=s(i,3);\n", +" g(n,m+1)='-';\n", +" m=m+2;\n", +" else\n", +" g(n,m)=strcat([s(i,3) s(j,3)]);\n", +" g(n,m+1)='-';\n", +" m=m+2;\n", +" for z=2:max(size(s(:,1)))\n", +" if(s(z,3)==s(z,1))\n", +" h(1,3)=s(z,2);\n", +" h(1,5)=s(z,3);\n", +" end\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"disp('Synchronizing tree for Machine M3 is ')\n", +"disp(f);\n", +"disp(g);\n", +"disp(h);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.3: Contracted_State_Machine.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"s=['PS' 'x=0' 'x=1';\n", +" 'A' 'A' 'B';\n", +" 'B' 'E' 'B';\n", +" 'C' 'E' 'F';\n", +" 'D' 'E' 'F';\n", +" 'E' 'A' 'D';\n", +" 'F' 'E' 'B'];\n", +"z=0;\n", +"disp('Original Machine M4');\n", +"disp(s);\n", +"p=s;\n", +"n=max(size(s(:,1)));\n", +"for i=2:n\n", +" for j=i:n\n", +" if(s(i,2)==s(j,2) & s(i,3)==s(j,3) & i~=j)\n", +" z=z+1;\n", +" for k=j:n-1\n", +" p(k,:)=p(k+1,:);\n", +" end\n", +" for k=2:n-1\n", +" if(p(k,2)==s(j,1))\n", +" p(k,2)=s(i,1);\n", +" end\n", +" if(p(k,3)==s(j,1))\n", +" p(k,3)=s(i,1);\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"s=p(1:n-z,:);\n", +"disp('The contracted Table M4');\n", +"disp(s);\n", +"p=s;\n", +"n=n-z;\n", +"z=0;\n", +"for i=2:n\n", +" for j=i:n\n", +" if(s(i,2)==s(j,2) & s(i,3)==s(j,3) & i~=j)\n", +" z=z+1;\n", +" for k=j:n-1\n", +" p(k,:)=p(k+1,:);\n", +" end\n", +" for k=2:n-1\n", +" if(p(k,2)==s(j,1))\n", +" p(k,2)=s(i,1);\n", +" end\n", +" if(p(k,3)==s(j,1))\n", +" p(k,3)=s(i,1);\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"s=p(1:n-z,:);\n", +"disp('Repeated Contractions of M4');\n", +"disp(s);\n", +"p=s;\n", +"n=n-z;\n", +"z=0;\n", +"for i=2:n\n", +" for j=i:n\n", +" if(s(i,2)==s(j,2) & s(i,3)==s(j,3) & i~=j)\n", +" z=z+1;\n", +" for k=j:n-1\n", +" p(k,:)=p(k+1,:);\n", +" end\n", +" for k=2:n-1\n", +" if(p(k,2)==s(j,1))\n", +" p(k,2)=s(i,1);\n", +" end\n", +" if(p(k,3)==s(j,1))\n", +" p(k,3)=s(i,1);\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"s=p(1:n-z,:);\n", +"disp(s);\n", +"p=s;\n", +"n=n-z;\n", +"z=0;\n", +"for i=2:n\n", +" for j=i:n\n", +" if(s(i,2)==s(j,2) & s(i,3)==s(j,3) & i~=j)\n", +" z=z+1;\n", +" for k=j:n-1\n", +" p(k,:)=p(k+1,:);\n", +" end\n", +" for k=2:n-1\n", +" if(p(k,2)==s(j,1))\n", +" p(k,2)=s(i,1);\n", +" end\n", +" if(p(k,3)==s(j,1))\n", +" p(k,3)=s(i,1);\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"s=p(1:n-z,:);\n", +"disp(s);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.4: Testing_Table.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"N=4;\n", +"s=[ 'PS' 'x=0' 'x=1';\n", +" 'A' 'A' 'B';\n", +" 'B' 'C' 'B';\n", +" 'C' 'A' 'D';\n", +" 'D' 'C' 'B'];\n", +"n=max(size(s(:,1)));\n", +"s(n+1,:)=['-' '-' '-'];\n", +"l=2;\n", +"for i=2:n\n", +" for j=i:n\n", +" if(i~=j)\n", +" s(n+l,1)=strcat([s(i,1) s(j,1)]);\n", +" s(n+l,2)=strcat([s(i,2) s(j,2)]);\n", +" s(n+l,3)=strcat([s(i,3) s(j,3)]);\n", +" l=l+1;\n", +" end\n", +" end\n", +"end\n", +"disp(s);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.6: Testing_graph.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"s=['PS' 'x=0' 'x=1';\n", +" 'A' 'A' 'B';\n", +" 'B' 'C' 'D';\n", +" 'C' 'D' 'C';\n", +" 'D' 'B' 'A'];\n", +"q=[0 0;0 0;1 1;1 1];\n", +"n=max(size(s(:,1)));\n", +"l=1;\n", +"for i=2:n\n", +" z=0;x=0;\n", +" for j=i:n\n", +" if(q(i-1,1)==0 & q(i-1,2)==0 & i~=j & z==0)\n", +" p(l,1)=s(i,1);\n", +" p(l,2)=strcat([s(i,2) s(i,3)]);\n", +" p(l,3)='-';\n", +" l=l+1;z=z+1;\n", +" else \n", +" if(q(i-1,1)==1 & q(i-1,2)==1 & x==0)\n", +" p(l,1)=s(i,1);\n", +" p(l,2)='-';\n", +" p(l,3)=strcat([s(i,2) s(i,3)]);\n", +" l=l+1;x=x+1;\n", +" end\n", +" end \n", +" end\n", +"end\n", +"disp(['PS' 'z=0' 'z=1']);\n", +"disp(p);\n", +"disp(['AB' '(AC)(AD)(BC)(BD)' '-';\n", +" 'CD' '-' '(AC)(AD)(BC)(BD)']);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.7: Testing_Table_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"s=['S' 'C1' 'SB1';\n", +" 'B1' 'S' '-';\n", +" 'C1' 'C2' '-';\n", +" 'C2' '-' 'S'];\n", +"n=max(size(s(:,1)));\n", +"l=1;\n", +"for i=1:n\n", +" for j=i:n\n", +" if(i~=j)\n", +" p(l,1)=strcat([s(i,1) s(j,1)]);\n", +" if(s(i,2)=='-' | s(j,2)=='-')\n", +" p(l,2)='-';\n", +" else\n", +" p(l,2)=strcat([s(i,2) s(j,2)]);\n", +" end\n", +" if(s(i,3)=='-' | s(j,3)=='-')\n", +" p(l,3)='-';\n", +" else\n", +" p(l,3)=strcat([s(i,3) s(j,3)]);\n", +" end\n", +" l=l+1;\n", +" end\n", +" end\n", +"end" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/15-Linear_Sequential_Machines.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/15-Linear_Sequential_Machines.ipynb new file mode 100644 index 0000000..555c493 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/15-Linear_Sequential_Machines.ipynb @@ -0,0 +1,461 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 15: Linear Sequential Machines" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.10: Reducable.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"A=[0 1 1;\n", +" 1 0 0;\n", +" 1 0 0];\n", +"B=[1;1;0];\n", +"C=[1 1 0;\n", +" 1 1 1];\n", +"D=[0;1];\n", +"K=[C;C*A;C*(A*A)];\n", +"K=modulo(K,2);\n", +"disp('K matrix')\n", +"disp(K);\n", +"disp(rank(K),'since the rank of K is ');\n", +"disp('K is not further reducible');\n", +"//z=K * y;" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.11: Linear_Machine.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"A=[0 1 0;\n", +" 1 0 0;\n", +" 0 1 1];\n", +"B=[1;1;1];\n", +"C=[1 0 0];\n", +"D=[1];\n", +"K=[C;C*A;C*(A*A)];\n", +"disp(K);\n", +"disp(rank(K),'rank of K matrix is ');\n", +"disp('Since the rank is 2 K matrix can be reduced');\n", +"disp('As only the first 2 rows are linearly independent therefore');\n", +"T=[1 0 0;0 1 0];\n", +"disp(T,'T =');\n", +"disp('In this case Q is');\n", +"Q=[1 0;0 1];\n", +"disp(Q);\n", +"Q_inv=inv(Q);\n", +"R=T';\n", +"//y_red=T*y;\n", +"A_red=T*A*R;\n", +"B_red=T*B;\n", +"C_red=C*R;\n", +"D_red=D;" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.12: Linear_Machine_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"A=[1 0 0 0;\n", +" 0 0 1 1;\n", +" 1 1 0 0;\n", +" 1 0 1 0];\n", +"B=[1 0;\n", +" 0 0;\n", +" 1 1;\n", +" 1 1];\n", +"C=[0 1 0 1;\n", +" 1 1 1 0];\n", +"D=[1 0;\n", +" 0 1];\n", +"K=[C;C*A;C*(A*A)];\n", +"K=modulo(K,2);\n", +"T=K(1:3,:);\n", +"Q=K(1:3,1:3);\n", +"Q_inv=inv(Q);\n", +"Q_inv=abs(modulo(Q_inv,2));\n", +"R=[Q_inv;[0 0 0]];\n", +"disp('Reduced matrix A is');\n", +"disp(A_red=T*A*R);\n", +"disp('Reduced matrix B is');\n", +"disp(B_red=T*B);\n", +"disp('Reduced matrix C is');\n", +"disp(C_red=C*R);\n", +"disp('Reduced matrix D is');\n", +"disp(D_red=D);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.15: Commutative_ring.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"n=4;\n", +"for i=1:4\n", +" for j=1:4\n", +" p(i,j)=modulo(i+j-2,4);\n", +" end\n", +"end\n", +"disp('modulo 4 Addition');\n", +"disp(p);\n", +"for i=1:4\n", +" for j=1:4\n", +" p(i,j)=modulo((i-1)*(j-1),4);\n", +" end\n", +"end\n", +"disp('modulo 4 Multiplication');\n", +"disp(p);\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.16: Identifying_Whether_the_Ring_is_a_Field_Or_not.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"n=4;\n", +"a=zeros(1,n);\n", +"for i=1:n\n", +" for j=1:n\n", +" pad(i,j)=modulo(i+j-2,4);\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" pmu(i,j)=modulo((i-1)*(j-1),4);\n", +" end\n", +"end\n", +"t=0;\n", +"for i=1:n\n", +" for j=1:n\n", +" if(pad(i,j)==1)\n", +" t=1;\n", +" break;\n", +" end\n", +" end\n", +"end\n", +"if(t==0)\n", +" disp('Modulo 4 ring is not a field');\n", +"end\n", +"for i=0:3\n", +" for j=0:3\n", +" if(modulo(i*j,4)==1)\n", +" a(i)=1;\n", +" end\n", +" end\n", +"end\n", +"res=0;\n", +"for i=1:max(size(a))\n", +" if(a(i)==1)\n", +" res=res+1;\n", +" end\n", +"end\n", +"if(res==4)\n", +" disp('Modulo 4 ring is a field');\n", +"else\n", +" disp('Modulo 4 ring is not a field');\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.17: Finite_Field.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"n=3;\n", +"for i=1:n\n", +" for j=1:n\n", +" p(i,j)=modulo(i+j-2,3);\n", +" end\n", +"end\n", +"disp('modulo 3 Addition');\n", +"disp(p);\n", +"for i=1:n\n", +" for j=1:n\n", +" p(i,j)=modulo((i-1)*(j-1),3);\n", +" end\n", +"end\n", +"disp('modulo 3 Multiplication');\n", +"disp(p);\n", +"" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.3: Transfer_function.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"T1=[1 2 1];\n", +"T2=[0 1 1];\n", +"n=max(size(T1));\n", +"a=n-1;\n", +"b=a;\n", +"T3=zeros(1,a+b+1);\n", +"for i=1:n\n", +" b=n-1;\n", +" for j=1:n\n", +" T3(a+b+1)=T3(a+b+1)+(T1(i)*T2(j));\n", +" b=b-1;\n", +" end\n", +" a=a-1;\n", +"end\n", +"m=max(size(T3));\n", +"i=1;\n", +"j=m;\n", +"while(i<=floor(m/2) & j>=(ceil(m/2)+1))\n", +" t=T3(i);\n", +" T3(i)=modulo(T3(j),3);\n", +" T3(j)=modulo(t,3);\n", +" i=i+1;\n", +" j=j-1;\n", +"end\n", +"T3(ceil(m/2))=modulo(T3(ceil(m/2)),3);\n", +"disp('Top row of the below matrix is powers of the transfer function and bottom row is of coefficients of respective powers');\n", +"disp([4 3 2 1 0]);\n", +"disp(T3);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.4: Impulse_response.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"T1=[1 0 1 1];\n", +"h=[1 1 0 1 0 0 0 0 0];\n", +"in=[1 0 1 1];\n", +"l=1;\n", +"for i=2:max(size(in(1,:)))\n", +" h1=h;\n", +" if(in(i)==1)\n", +" for k=1:i-1\n", +" t=h1(max(size(h1(1,:))));\n", +" for j=max(size(h1(1,:)))-1:-1:1\n", +" h1(j+1)=h1(j);\n", +" end\n", +" h1(1)=t;\n", +" end\n", +" D(l,:)=h1(1,:);\n", +" l=l+1;\n", +" end\n", +"end\n", +"output=h+D(1,:)+D(2,:);\n", +"output=modulo(output,2);\n", +"disp(output);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.5: Null_Sequence.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//T=1+D+D^3 over GF(2)\n", +"//let X0 is the null sequence\n", +"//0=X0+DX0+D^3X0 since output of the null sequence is zero\n", +"//Adding X0 on both sides we get X0=DX0+D^3X0\n", +"nul=[0 0 1];\n", +"T=[0 1 0 1];\n", +"j=1;\n", +"for i=1:max(size(T));\n", +" if(T(i)==1)\n", +" s(1,j)=i-1;\n", +" j=j+1;\n", +" end\n", +"end\n", +"j=4;\n", +"for i=1:7\n", +" nul(1,j)=nul(1,j-s(1))+nul(1,j-s(2));\n", +" nul(1,j)=modulo(nul(1,j),2);\n", +" j=j+1;\n", +"end\n", +"disp('Null Sequence for input 001 is ');\n", +"disp(nul);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.6: Null_Sequence_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//T=1+2D^2+D^3 over GF(3)\n", +"//let X0 is the null sequence\n", +"//0=X0+2D^2*X0+D^3*X0 since output of the null sequence is zero\n", +"//Adding X0 on both sides we get 2X0=2D^2*X0+D^3*X0\n", +"//X0=D^2*X0+2D^3*X0\n", +"nul=[1 1 1];\n", +"T=[0 0 1 2];\n", +"j=1;\n", +"for i=1:max(size(T));\n", +" if(T(i)>=1)\n", +" s(1,j)=i-1;\n", +" j=j+1;\n", +" end\n", +"end\n", +"j=4;\n", +"for i=1:15\n", +" nul(1,j)=nul(1,j-s(1))+2*nul(1,j-s(2));\n", +" nul(1,j)=modulo(nul(1,j),3);\n", +" j=j+1;\n", +"end\n", +"disp('Null Sequence for input 001 is ');\n", +"disp(nul);" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/16-Finite_State_Recognizers.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/16-Finite_State_Recognizers.ipynb new file mode 100644 index 0000000..bf3ba8c --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/16-Finite_State_Recognizers.ipynb @@ -0,0 +1,85 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 16: Finite State Recognizers" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.2: Prove_the_identity.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('R1=λ+1*(011)*(1*(011)*)*');\n", +"//from the identity λ+RR*=R* where R=1*(011)*\n", +"disp('R2=(1+011)*');\n", +"//from the identity (P+Q)*=(P*Q*)*\n", +"disp('R1=λ+1*(011)*(1*(011)*)*');\n", +"disp('(1*(011)*)*');\n", +"disp('(1+011)*=R2');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.3: Prove_the_identity_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('(1+00*1)+(1+00*1)(0+10*1)*(0+10*1)=0*1(0+10*1)*');\n", +"disp('(1+00*1)+(1+00*1)(0+10*1)*(0+10*1)');\n", +"//by taking (1+00*1) as common\n", +"disp('=(1+00*1)[λ+(0+10*1)*(0+10*1)]');\n", +"disp('[(λ+00*)1][λ+(0+10*1)*(0+10*1)]');\n", +"//from the identity λ+RR*=R*\n", +"disp('[0*1(0+10*1)*]');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/2-Sets_Relations_and_Lattices.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/2-Sets_Relations_and_Lattices.ipynb new file mode 100644 index 0000000..7655d03 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/2-Sets_Relations_and_Lattices.ipynb @@ -0,0 +1,569 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 2: Sets Relations and Lattices" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.11: Partial_Ordering_Divisibilty_Relation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//N=input('enter the number for which divisibilty ');\n", +"N=45; //divident\n", +"h=1;\n", +"for i=1:N //finding all the divisors of 45\n", +" if(modulo(N,i)==0)\n", +" r(h)=i;\n", +" h=h+1;\n", +" end\n", +"end\n", +"n=max(size(r));\n", +"disp('Hasse Diagram') //displaying in the form of hasse diagram\n", +"disp('------------')\n", +"disp(r(n));\n", +"h=2;\n", +"for i=n-1:-2:3\n", +" disp('-----------');\n", +" disp(r(i),r(i-1));\n", +" h=h+1;\n", +"end\n", +"disp('----------')\n", +"disp(r(1));" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.12: Ordering_Relation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc\n", +"N=4;\n", +"//defining all the partial ordered sets\n", +"s(1,:)=[1 0];\n", +"s(2,:)=[0 1];\n", +"s(3,:)=[0 0];\n", +"s(4,:)=[1 1];\n", +"//Finding \n", +"a=1;b=1;\n", +"for i=1:1:N //sorting based on the level\n", +" for j=i:1:N\n", +" if(i~=j)\n", +" u=s(i,1)+s(i,2);\n", +" v=s(j,1)+s(j,2);\n", +" if(u<v)\n", +" temp(1)=s(i,1);\n", +" temp(2)=s(i,2);\n", +" s(i,1)=s(j,1);\n", +" s(i,2)=s(j,2);\n", +" s(j,1)=temp(1);\n", +" s(j,2)=temp(2);\n", +" end\n", +" end\n", +" end\n", +"end\n", +"// displaying in the form of hasse graph form\n", +"disp('1st stage of Hasse diagram');\n", +"disp(s(1,:));\n", +"disp('2nd stage of Hasse diagram');\n", +"disp(s(2,:));\n", +"disp(s(3,:));\n", +"disp('3rd stage of Hasse diagram');\n", +"disp(s(4,:));" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.15: Lattice_Of_subsets.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc\n", +"N=3;\n", +"s=['a' 'b' 'c']; //set for which lattice should be defined\n", +"for i=2:2^3\n", +" s(i,:)=s(1,:);\n", +"end\n", +"//defining 2nd level vertices of the lattice\n", +"for i=2:4\n", +" s(i,i-1)='0';\n", +"end\n", +"//defining 3rd level vertices of the lattice\n", +"for i=5:6\n", +" s(i,i-4)='0';\n", +" s(i,i-3)='0';\n", +"end\n", +"s(7,1)='0';s(7,3)='0';\n", +"//defining the final level of vertices of the lattice\n", +"s(8,:)=['0' '0' '0'];\n", +"disp('1st level');\n", +"disp(s(1,:));\n", +"disp('2nd level');\n", +"disp(s(2,:));\n", +"disp(s(3,:));\n", +"disp(s(4,:));\n", +"disp('3rd level');\n", +"disp(s(5,:));\n", +"disp(s(6,:));\n", +"disp(s(7,:));\n", +"disp('4th level');\n", +"disp(s(8,:));" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.16: glb_and_ulb.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"par1=['ab','cde','fh','gi']; //initial partitions par1\n", +"par2=['abc','de','fg','hi']; //partition 2 \n", +"//par=par1+par2;\n", +"//lub-lower upper bound\n", +"par_lub=['abcde','fghi'];\n", +"disp(par_lub);\n", +"//par=par1.par2\n", +"//glb-greatest lower bound\n", +"par_glb=['ab','c','de','f','g','h','i'];\n", +"disp(par_glb);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1: Set_Of_All_even_Numbers.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//lower=input('input the lower limit of the set');\n", +"//upper=input('input the upper limit of the set');\n", +"lower=1; //lower limit of the set \n", +"upper=10; //upper limit of the set\n", +"temp=lower;\n", +"h=1;i=1;\n", +"while(temp<=upper)\n", +" if(modulo(temp,2)==0) //checking whether a number is even or not\n", +" e(h)=temp;\n", +" h=h+1;\n", +" else\n", +" o(i)=temp; //odd number \n", +" i=i+1;\n", +" end\n", +" temp=temp+1;\n", +"end;\n", +"disp('the set of even number between the limits')\n", +"disp(e);\n", +"disp('the set of odd number between the limits')\n", +"disp(o);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.2: Subsets_Of_a_Faces_of_a_die.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//N=input('enter the elements in the set');\n", +"//n=1;\n", +"//while(n<=N)\n", +"// i(n)=input('enter the elements of first set');\n", +"// n=n+1;\n", +"//end;\n", +"N=6;\n", +"i(1)='f1';i(2)='f2';i(3)='f3';i(4)='f4';i(5)='f5';i(6)='f6';\n", +"disp('null set'); //since null set is subset of any set.\n", +"for a=1:1:N //set of single elements\n", +" disp(i(a));\n", +"end\n", +"c=1;\n", +"for a=1:1:N-1 //set of two elements\n", +" for b=a:1:N\n", +" if(a~=b)\n", +" m(c,1)=i(a);\n", +" m(c,2)=i(b);\n", +" c=c+1;\n", +" end\n", +" end;\n", +"end;\n", +"disp(m);\n", +"d=1;\n", +"for a=1:1:N //set of three elements\n", +" for b=a:1:N\n", +" for c=b:1:N\n", +" if((a~=b)&(b~=c)&(c~=a))\n", +" p(d,1)=i(a);\n", +" p(d,2)=i(b);\n", +" p(d,3)=i(c);\n", +" d=d+1;\n", +" end\n", +" end\n", +" end\n", +"end\n", +"disp(p);\n", +"e=1;\n", +"for a=1:1:N //set of four elements\n", +" for b=a:1:N\n", +" for c=b:1:N\n", +" for d=c:1:N\n", +" if((a~=b)&(b~=c)&(c~=d)&(d~=a)&(b~=d)&(a~=c))\n", +" q(e,1)=i(a);\n", +" q(e,2)=i(b);\n", +" q(e,3)=i(c);\n", +" q(e,4)=i(d)\n", +" e=e+1;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"disp(q);\n", +"f=1;\n", +"for a=1:1:N //set of five elements\n", +" for b=a:1:N\n", +" for c=b:1:N\n", +" for d=c:1:N\n", +" for e=d:1:N\n", +" if((a~=b)&(b~=c)&(c~=d)&(d~=e)&(e~=a)&(a~=c)&(a~=d)&(b~=d)&(c~=e)&(b~=e))\n", +" r(f,1)=i(a);\n", +" r(f,2)=i(b);\n", +" r(f,3)=i(c);\n", +" r(f,4)=i(d);\n", +" r(f,5)=i(e);\n", +" f=f+1;\n", +" end\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"disp(r);\n", +"for a=1:1:N //set of six elements\n", +" s(1,1)=i(1);\n", +" s(1,2)=i(2);\n", +" s(1,3)=i(3);\n", +" s(1,4)=i(4);\n", +" s(1,5)=i(5);\n", +" s(1,6)=i(6);\n", +"end\n", +"disp(s);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.4: Relation_between_two_sets.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"N1=2;\n", +"N2=3;\n", +"//n=1;\n", +"//while(n<=N1)\n", +"// i(n)=input('enter the elements of first set');\n", +"// n=n+1;\n", +"//end;\n", +"i=['p' 'q']; //set A\n", +"//n=1;\n", +"//while(n<=N2)\n", +"// j(n)=input('enter the elements of second set');\n", +"// n=n+1;\n", +"//end;\n", +"j=['r' 's' 't']; //set B\n", +"c=1;d=1;\n", +"for a=1:1:N1 //realtion between sets A and B\n", +" for b=1:1:N2\n", +" m(c,d)=i(a);\n", +" m(c,d+1)=j(b);\n", +" c=c+1;\n", +" end;\n", +"end;\n", +"disp(m);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.5: Equivalence_relation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//N=input('enter the no of elements in the set :');\n", +"//for i=1:1:N\n", +"// s(1,i)=input('enter the elements in the set :');\n", +"//end;\n", +"//n=input('enter the number of pairs in the relation :');\n", +"//for j=1:1:n\n", +"// for k=1:1:2\n", +"// r(j,k)=input('enter the elements in the relation :');\n", +"// end\n", +"//end\n", +"N=2;\n", +"s=['a' 'b']; //elements in the set\n", +"n=3;\n", +"r=['a' 'a';'b' 'b';'a' 'b']; //realtion between the elements in the above set.\n", +"ref=zeros(1,N);\n", +"for a=1:1:N\n", +" for b=1:1:n\n", +" if(r(b,1)==s(1,a)&r(b,2)==s(1,a))\n", +" ref(1,a)=1;\n", +" end\n", +" end\n", +"end\n", +"for i=1:1:N //checking whether above relation is reflexive or not\n", +" if(ref(1,i)==1)\n", +" disp('the above relation is reflexive with elements ');\n", +" disp(s(1,i));\n", +" disp(' ');\n", +" end\n", +"end\n", +"sym=zeros(1,(N*N-1)/2);\n", +"s(1,N+1)=s(1,1);\n", +"for a=1:1:N //checking whether above relation is symmetric or not\n", +" for b=1:1:n\n", +" if(r(b,1)==s(1,a)&r(b,2)==s(1,a+1))\n", +" for d=1:1:n\n", +" if(r(d,1)==s(1,a+1)&r(d,2)==s(1,a))\n", +" sym(1,a)=1;\n", +" disp('the above relation is symmetric for these pairs :');\n", +" disp(')',s(1,a+1),s(1,a),'(');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for a=1:1:n //checking whether it is transtive or not.\n", +" u=r(a,1);\n", +" v=r(a,2);\n", +" for b=a:1:n\n", +" if(r(b,1)==v)\n", +" w=r(b,2);\n", +" for c=b:1:n\n", +" if(r(c,1)==w&r(c,2)==u)\n", +" disp('satisfies transtitve property');\n", +" abort;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.6: Equivalence_relation_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//N=input('enter the elements in the set :');\n", +"//for i=1:1:N\n", +"// s(i)=input('enter the elements :');\n", +"//end\n", +"N=2;\n", +"s=['a' 'b'];\n", +"disp('The equivalence relation of above set is :');\n", +"h=1;\n", +"for i=1:1:N //to satisfy reflexive property\n", +" ref(h,1)=s(i);\n", +" ref(h,2)=s(i);\n", +" h=h+1;\n", +"end\n", +"for i=1:1:N //to satisfy symmetric property\n", +" for j=i:1:N\n", +" if(i~=j)\n", +" ref(h,1)=s(i);\n", +" ref(h,2)=s(j);\n", +" h=h+1;\n", +" end\n", +" end\n", +"end\n", +"m=1;\n", +"for i=1:max(size(ref(:,1))) //to satisfy transtive property\n", +" if(ref(i,1)~=ref(i,2))\n", +" ref1(m,1)=ref(i,2);\n", +" ref1(m,2)=ref(i,1);\n", +" m=m+1;\n", +" end\n", +"end\n", +"disp(ref);\n", +"disp(ref1);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.7: Function_Check.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//n1=input('enter the no of elements in the 1st set');\n", +"//for i=1:1:n1\n", +"// s1(i)=input('enter the elements of 1st set:');\n", +"//end\n", +"n1=3;\n", +"s1=['a1' 'a2' 'a3']; //set A\n", +"//n2=input('enter the no of elements in the 2nd set');\n", +"//for i=1:1:n2\n", +"// s2(i)=input('enter the elements of 2ns set:');\n", +"//end\n", +"n2=2;\n", +"s1=['b1' 'b2']; //set B\n", +"//N=input('enter the pairs in the relation which you want to check whether is a function');\n", +"//for i=1:1:N\n", +"// for j=1:1:2\n", +"// r(i,j)=input('enter the elements in the relation:');\n", +"// end\n", +"//end\n", +"N=3;\n", +"r=['a1' 'b1';'a2' 'b2';'a2' 'b1']; //Realtion r\n", +"for i=1:1:N //checks whether the relation is function or not\n", +" for j=i:1:N\n", +" if(r(i,1)==r(j,1) & i~=j)\n", +" disp('the relation is not a function');\n", +" abort;\n", +" end\n", +" end\n", +"end\n", +"disp('the realtion is a fucntion');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/3-Switching_Algebra_And_Its_Applications.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/3-Switching_Algebra_And_Its_Applications.ipynb new file mode 100644 index 0000000..046f100 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/3-Switching_Algebra_And_Its_Applications.ipynb @@ -0,0 +1,508 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 3: Switching Algebra And Its Applications" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.10: Tabulate_the_Function_of_2_variables.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"a1=0;a2=a1;a3=a1;\n", +"//all combinations of 2 varible inputs\n", +"f(:,1)=[0;0;1;1];\n", +"f(:,2)=[0;1;0;1];\n", +"disp('The turth table of f for all the combinations of a0,a1,a2,a3 are shown below')\n", +"//determining the values of f for all combinations of a0,a1,a2,a3\n", +"for a3=0:1\n", +" for a2=0:1\n", +" for a1=0:1\n", +" for a0=0:1\n", +" disp([' a3' ' a2' ' a1' ' a0']);\n", +" disp([a3 a2 a1 a0]);\n", +" i=1;\n", +" for x=0:1\n", +" for y=0:1\n", +" f0=bitand(a0,bitand(bitcmp(x,1),bitcmp(y,1)));\n", +" f1=bitand(a1,bitand(bitcmp(x,1),y));\n", +" f2=bitand(a2,bitand(x,bitcmp(y,1)));\n", +" f3=bitand(a3,bitand(x,y));\n", +" f4=bitor(f0,f1);\n", +" f5=bitor(f2,f3);\n", +" f(i,3)=bitor(f4,f5);\n", +" i=i+1;\n", +" end\n", +" end\n", +" disp([' x' ' y' ' f']);\n", +" disp(f);\n", +" disp('*--------------------*');\n", +" end\n", +" end\n", +" end\n", +"end" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.11: NOR.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('x NOR x=(x+x)^');\n", +"disp('NOT Gate');\n", +"disp('x NOR x=x^x^=x^');\n", +"disp('OR Gate');\n", +"disp('(x NOR y) NOR (x NOR y) = (x^ NOR y^)^ = x+y');\n", +"disp('AND Gate');\n", +"disp('(x NOR x) NOR (y NOR y )= x^ NOR y^ = xy');\n", +"disp('NAND Gate');\n", +"disp(' NOT ((x NOR x) NOR (y NOR y))= NOT (x^ NOR y^) = NOT(xy) = (xy)^');\n", +"disp('XOR Gate');\n", +"disp('(x^ NOR y^) NOR (x NOR y) = x^y+xy^');\n", +"disp('XNOR Gate');\n", +"disp('(x^ NOR y) NOR (x NOR y^) = xy+x^y^');\n", +"disp('Since every other gate can be implemented using NOR gate it is said to be functionally complete')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.12: Transmission_function.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('T=xy^+(x+y^)z');\n", +"disp('from the identity a+a^b=a+b');\n", +"disp('T=xy^+z');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.13: Air_Conditioning_System.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('Air conditioning system of a storage warehouse will be turned on if and only if it satisfies these conditions');\n", +"disp('let W denotes weight of 100 tons or more');\n", +"disp('H denotes relative humidity of atleast 60 percent');\n", +"disp('T denotes temparature above 60 degrees');\n", +"disp('P denotes barometric pressure of 30 or more');\n", +"disp('*-first condition-*');\n", +"disp('W<100 tons => W^ ,H>=60 => H , T>60 ');\n", +"disp('A1=W^HT');\n", +"disp('*-second condition-*');\n", +"disp('W>100 tons => W , T>60 => T');\n", +"disp('A2=WT');\n", +"disp('*-third condition-*');\n", +"disp('W<100 tons => W^ ,P>30 => P');\n", +"disp('A3=W^P');\n", +"disp('since Air condtioning system should be activated if any one of the above is satisfied so ');\n", +"disp('A=A1+A2+A3');\n", +"disp('A=W^HT+WT+W^P');\n", +"disp('A=T(W^H+W)+W^P');\n", +"disp('A=T(W+H)+W^P');\n", +"disp('Thus a combinational system with above expression makes the air conditioning system on when required')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.14: DeMorgans_Law.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"i=1;\n", +"//all combinations of 2 variable inputs\n", +"f(:,1)=[0;0;1;1];\n", +"f(:,2)=[0;1;0;1];\n", +"//verifying D'morgan first law\n", +"for a=0:1\n", +" for b=0:1\n", +" f(i,3)=bitcmp(bitor(a,b),1);\n", +" f(i,4)=bitand(bitcmp(a,1),bitcmp(b,1));\n", +" i=i+1;\n", +" end\n", +"end\n", +"disp(' a b (a+b)^ a^b^');\n", +"disp(f);\n", +"disp('Therefore (a+b)^=a^ b^ ');\n", +"//verfying D'morgan 2nd law\n", +"i=1;\n", +"for a=0:1\n", +" for b=0:1\n", +" f(i,3)=bitcmp(bitand(a,b),1);\n", +" f(i,4)=bitor(bitcmp(a,1),bitcmp(b,1));\n", +" i=i+1;\n", +" end\n", +"end\n", +"disp(' a b (ab)^ a^+b^');\n", +"disp(f);\n", +"//proving D'morgans laws theoritically\n", +"disp('(a+b)^=a^.b^');\n", +"disp('(a.b)^=a^+b^');\n", +"disp('we have show that (a+b)(a+b)^=0 and (a+b)+a^.b^=1');\n", +"disp('(a+b)a^b^=aa^b^+ba^b^=0+a^bb^=0+0=0');\n", +"disp('(a+b)+a^b^=a+b+a^b^=a+b+a^=b+a+a^=b+1=1');\n", +"disp('This proves the first Dmorgan law and in the similar way 2nd law can also be proved');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.1: Simplify_1.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc;\n", +"disp('T(x,y,z)=x^y^z+yz+xz');\n", +"disp('**Minimise the given expression**');\n", +"disp('**Since z is common in every term taking z common**');\n", +"disp('T(x,y,z)=z(x^y^+y+x)');\n", +"disp('**From the property a+a^b=a+b **');\n", +"disp('T(x,y,z)=z(x^+y+x)');\n", +"disp('**Since we know that a+a^=1 **');\n", +"disp('T(x,y,z)=z(1+y)');\n", +"disp('**we know that 1+a=1 **');\n", +"disp('T(x,y,z)=z.1');\n", +"disp('T(x,y,z)=z');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.2: Simplify_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc\n", +"disp('T(x,y,z)=(x+y)[x^(y^+z^)]^+x^y^+x^z^');\n", +"disp('From the properties 1. (ab)^=a^+b^ 2. (a+b)^=a^b^');\n", +"disp('T(x,y,z)=((x+y)(x+yz))+x^y^+x^z^');\n", +"disp('Multipliying the first 2 terms');\n", +"disp('T(x,y,z)=(x+xyz+xy+yz)+x^y^+x^z^');\n", +"disp('T(x,y,z)=(x(1+y+yz)+yz)+x^y^+x^z^');\n", +"disp('T(x,y,z)=x+yz+x^y^+x^z^');\n", +"disp('we know a+a^b=a+b');\n", +"disp('T(x,y,z)=x+y^+yz+x^z^');\n", +"disp('T(x,y,z)=x+z^+y^+yz');\n", +"disp('T(x,y,z)=x+z^+y^+z');\n", +"disp('since z+z^=1');\n", +"disp('T(x,y,z)=x+1+y^');\n", +"disp('T(x,y,z)=1')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.3: Prove_the_identity.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc;\n", +"disp('L.H.S = xy+x^y^+yz');\n", +"disp('R.H.S = xy+x^y^+x^z');\n", +"disp('Based on consensus theorem')\n", +"disp('we can write x^y^+yz as x^y^+yz+x^z bcoz the two expressions are equal');\n", +"disp('(x^y^+yz+x^z(y+y^))=x^y^+yz+x^yz+x^y^z');\n", +"disp('x^y^+yz+x^yz+x^y^z=x^y^(1+z)+yz(1+x^)');\n", +"disp('x^y^+yz=x^y^+yz+x^z');\n", +"disp('so L.H.S=xy+x^y^+yz=xy+x^y^+yz+x^z');\n", +"disp('In the similar way xy+yz+x^z can be simplified as xy+x^z');\n", +"disp('so L.H.S becomes xy+x^z+x^y^');\n", +"disp('thus L.H.S= R.H.S');\n", +"disp('hence proved')" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.4: Determine_The_Output_of_expression.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"//function definition\n", +"x=[0;0;0;0;1;1;1;1];\n", +"y=[0;0;1;1;0;0;1;1];\n", +"z=[0;1;0;1;0;1;0;1];\n", +"f=[1;0;1;1;0;0;1;1];\n", +"g=[0;1;0;1;1;0;1;0];\n", +"//calculating the values of expressions given\n", +"forg=bitor(f,g);\n", +"fandg=bitand(f,g);\n", +"fcmp=bitcmp(f,1);\n", +"s(:,1)=x;\n", +"s(:,2)=y;\n", +"s(:,3)=z;\n", +"s(:,4)=f;\n", +"s(:,5)=g;\n", +"s(:,6)=forg;\n", +"s(:,7)=fandg;\n", +"s(:,8)=fcmp;\n", +"p=[' x',' y',' z',' f',' g',' f+g',' fg',' f^'];\n", +"disp(p);\n", +"disp(s);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.5: Simplify_3.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('T(A,B,C,D)=A^C^+ABD+BC^D+AB^D^+ABCD^');\n", +"disp('Assume A^=x , C^=y , BD=z');\n", +"disp('Now from consensus theorem for the first three terms');\n", +"disp('BC^D is the redundant term so it can be removed');\n", +"disp('T(A,B,C,D)=A^C^+ABD+AB^D^+ABCD^');\n", +"disp('T(A,B,C,D)=A^C^+ABD+AD^(B^+BC)');\n", +"disp('we know that a+a^b=a+b');\n", +"disp('T(A,B,C,D)=A^C^+ABD+AD^(B^+C)');\n", +"disp('T(A,B,C,D)=A^C^+A(BD+D^(B^+C))');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.6: Simplify_4.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear\n", +"clc\n", +"disp('T(A,B,C,D)=A^B+ABD+AB^CD^+BC');\n", +"disp('T(A,B,C,D)=B(A^+AD)+C(AD^B^+B)');\n", +"disp('T(A,B,C,D)=B(A^+D)+C(AD^+B)');\n", +"disp('T(A,B,C,D)=A^B+BD+ACD^+BC');\n", +"disp('T(A,B,C,D)=A^B+BD+ACD^+BC(A+A^)');\n", +"disp('T(A,B,C,D)=A^B+A^BC+ABC+BD+ACD^');\n", +"disp('T(A,B,C,D)=A^B(1+C)+ABC+BD+ACD^');\n", +"disp('T(A,B,C,D)=A^B+ABC+BD+ACD^');\n", +"disp('**Now apply consensus theorem for 2nd 3rd and 4th terms**');\n", +"disp('let x=D,y=B,z=AC');\n", +"disp('T(A,B,C,D)=A^B+BD+ACD^');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.7: Expand_the_Expression.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('T(x,y,z)=x^y+z^+xyz');\n", +"disp('**To determine the canonical sum of products we have to check for a product which is not a min term and then multiply with the missing variable such that the expression value doesnt change**');\n", +"disp('T(x,y,z)=x^y(z+z^)+(x+x^)(y+y^)z^+xyz');\n", +"disp('T(x,y,z)=x^yz+x^yz^+xyz^+xy^z^+x^yz^+x^y^z^+xyz');\n", +"disp('T(x,y,z)=x^yz+x^yz^+xyz^+xy^z^+x^y^z^+xyz');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.8: Expand_the_Expression_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('T(x,y,z)=x^(y^+z)');\n", +"disp('**To determine the canonical product of sums form you need to check for a product which is not a max term and then add it with the missing terms such that the expression value is not altered**');\n", +"disp('T(x,y,z)=(x^+yy^+zz^)(xx^+y^+z)');\n", +"disp('a+b+cc^ can be written as product of 2 max terms (a+b+c)(a+b+c^)');\n", +"disp('a+bb^+cc^ can be written as (a+b+c)(a+b+c^)(a+b^+c)(a+b^+c^)');\n", +"disp('from the above two properties we can write the T(x,y,z) as');\n", +"disp('T(x,y,z)=(x^+y+z)(x^+y+z^)(x^+y^+z)(x^+y^+z^)(x+y^+z)(x^+y^+z)');\n", +"disp('T(x,y,z)=(x^+y+z)(x^+y+z^)(x^+y^+z)(x^+y^+z^)(x+y^+z)');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.9: POS.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clear;\n", +"clc;\n", +"disp('T(x,y,z)=x^y^z^+x^y^z+x^yz+xyz+xy^z+xy^z^');\n", +"disp('the complement T^ consists of those minterms which are not contained in the expression for T');\n", +"disp('T=[x^yz^+xyz^]^');\n", +"disp('(x+y^+z)(x^+y^+z)');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/4-Minimization_Of_Switching_Functions.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/4-Minimization_Of_Switching_Functions.ipynb new file mode 100644 index 0000000..60afc5a --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/4-Minimization_Of_Switching_Functions.ipynb @@ -0,0 +1,1773 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 4: Minimization Of Switching Functions" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.10: Cyclic_Prime_Implicant_map.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"k=[1 1 0 1;\n", +" 0 1 1 1];\n", +"karmap3(k);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.1: Irredundant_expressions.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"n=4; //four variable kmap\n", +"k=[1 1 0 1;\n", +" 0 1 1 1;\n", +" 0 1 1 0;\n", +" 0 0 0 0];\n", +"k(:,:,2)=zeros(n,n); //temporary matrix to know whether a element is paired or not\n", +"//declaring notations to display output\n", +"var=['y' 'z' 'w' 'x'];\n", +"p1=['y''z''' 'y''z' 'yz' 'yz'''];\n", +"p2=['w''x''';'w''x';'wx';'wx'''];\n", +"//minimum redundant elements accepted while pairing\n", +"cmn4=4;\n", +"cmn2=2;\n", +"temp=1;\n", +"disp('The minimal ecpression of the given Kmap ');\n", +"disp(k(:,:,1));\n", +"disp('is :');\n", +"disp(' ')\n", +"//16 cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j)~=1)\n", +" temp=0;\n", +" break;\n", +" end\n", +" end\n", +"end\n", +"printf('f=');\n", +"if(temp==1)\n", +" printf('1');\n", +" abort;\n", +"end\n", +"//8 cells\n", +"z1=ones(2,4);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,:,1);k(t,:,1)];\n", +" if(z==z1)\n", +" k(i,:,2)=[1 1 1 1];\n", +" k(t,:,2)=[1 1 1 1];\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"z2=ones(4,2);\n", +"for j=1:n\n", +" if(j==4)\n", +" t=1;\n", +" else\n", +" t=j+1;\n", +" end\n", +" z=[k(:,j,1) k(:,t,1)];\n", +" if(z==z2)\n", +" k(:,j,2)=[1;1;1;1];\n", +" k(:,t,2)=[1;1;1;1];\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//4 cells\n", +"z1=ones(1,4);\n", +"z2=ones(4,1);\n", +"z3=ones(2,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for t=1:n\n", +" z=k(t,:,1);\n", +" no=number_of(k(t,:,2),1);\n", +" if(z==z1 & no<cmn4)\n", +" k(t,:,2)=z1;\n", +" a=strsplit(temp1(1,t));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for t=1:n\n", +" z=k(:,t,1);\n", +" no=number_of(k(:,t,2),1);\n", +" if(z==z2 & no<cmn4)\n", +" k(:,t,2)=z2;\n", +" a=strsplit(temp2(t,1));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z4=[k(i,j,1) k(i,t2,1);k(t1,j,1) k(t1,t2,1)];\n", +" z5=[k(i,j,2) k(i,t2,2);k(t1,j,2) k(t1,t2,2)];\n", +" no=number_of(z5,1);\n", +" if(z4==z3 & no<cmn4)\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" k(t1,j,2)=1;\n", +" k(t1,t2,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"//2 cells\n", +"z6=[1 1];\n", +"z7=z6';\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z8=[k(i,j,1) k(i,t2,1)];\n", +" z9=[k(i,j,2) k(i,t2,2)];\n", +" no1=number_of(z9,1);\n", +" if(z8==z6 & no1<cmn2 & i+j~=2)\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p1(1,i));\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p1(1,i));\n", +" printf(var(2+in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z10=[k(i,j,1);k(t1,j,1)];\n", +" z11=[k(i,j,2);k(t1,j,2)];\n", +" no2=number_of(z11,1);\n", +" if(z10==z7 & no2<cmn2)\n", +" k(i,j,2)=1;\n", +" k(t1,j,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p2(j,1));\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p2(j,1));\n", +" printf(var(in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//single cell\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j,2)==0 & k(i,j,1)==1)\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp2(i,1));\n", +" for in=1:max(size(a(:,1)))\n", +" if(a(in,1)=='1')\n", +" printf(var(in+2));\n", +" else\n", +" if(a(in,1)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" end\n", +" end\n", +" for in=1:max(size(b(:,1)))\n", +" if(b(in,1)=='1')\n", +" printf(var(in));\n", +" else\n", +" if(b(in,1)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" end\n", +" end\n", +" if(i~=4 & j~=4)\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +"end\n", +"printf('0');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.2: Irredundant_expressions_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"n=4; //four variable kmap\n", +"k=[1 1 0 1;\n", +" 0 1 1 1;\n", +" 0 1 1 0;\n", +" 0 0 0 0];\n", +"k(:,:,2)=zeros(n,n); //temporary matrix to know whether a element is paired or not\n", +"//declaring notations to display output\n", +"var=['y' 'z' 'w' 'x'];\n", +"p1=['y^z^' 'y''z' 'yz' 'yz'''];\n", +"p2=['w^x^';'w''x';'wx';'wx'''];\n", +"//minimum redundant elements accepted while pairing\n", +"cmn4=1;\n", +"cmn2=1;\n", +"temp=1;\n", +"disp('The minimal ecpression of the given Kmap ');\n", +"disp(k(:,:,1));\n", +"disp('is :');\n", +"disp(' ')\n", +"//16 cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j)~=1)\n", +" temp=0;\n", +" break;\n", +" end\n", +" end\n", +"end\n", +"printf('f=');\n", +"if(temp==1)\n", +" printf('1');\n", +" abort;\n", +"end\n", +"//8 cells\n", +"z1=ones(2,4);\n", +"z2=ones(4,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,:,1);k(t,:,1)];\n", +" if(z==z1)\n", +" k(i,:,2)=[1 1 1 1];\n", +" k(t,:,2)=[1 1 1 1];\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for j=1:n\n", +" if(j==4)\n", +" t=1;\n", +" else\n", +" t=j+1;\n", +" end\n", +" z=[k(:,j,1) k(:,t,1)];\n", +" if(z==z2)\n", +" k(:,j,2)=[1;1;1;1];\n", +" k(:,t,2)=[1;1;1;1];\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//4 cells\n", +"z1=ones(1,4);\n", +"z2=ones(4,1);\n", +"z3=ones(2,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for t=1:n\n", +" z=k(t,:,1);\n", +" no=number_of(k(t,:,2),1);\n", +" if(z==z1 & no<cmn4)\n", +" k(t,:,2)=z1;\n", +" a=strsplit(temp1(1,t));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for t=1:n\n", +" z=k(:,t,1);\n", +" no=number_of(k(:,t,2),1);\n", +" if(z==z2 & no<cmn4)\n", +" k(:,t,2)=z2;\n", +" a=strsplit(temp2(t,1));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z4=[k(i,j,1) k(i,t2,1);k(t1,j,1) k(t1,t2,1)];\n", +" z5=[k(i,j,2) k(i,t2,2);k(t1,j,2) k(t1,t2,2)];\n", +" no=number_of(z5,1);\n", +" if(z4==z3 & no<cmn4)\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" k(t1,j,2)=1;\n", +" k(t1,t2,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"//2 cells\n", +"z6=[1 1];\n", +"z7=z6';\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z8=[k(i,j,1) k(i,t2,1)];\n", +" z9=[k(i,j,2) k(i,t2,2)];\n", +" no1=number_of(z9,1);\n", +" if(z8==z6 & no1<cmn2)\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p1(1,i));\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p1(1,i));\n", +" printf(var(2+in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z10=[k(i,j,1);k(t1,j,1)];\n", +" z11=[k(i,j,2);k(t1,j,2)];\n", +" no2=number_of(z11,1);\n", +" if(z10==z7 & no2<cmn2)\n", +" k(i,j,2)=1;\n", +" k(t1,j,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p2(j,1));\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p2(j,1));\n", +" printf(var(in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//single cell\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j,2)==0 & k(i,j,1)==1)\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp2(i,1));\n", +" for in=1:max(size(a(:,1)))\n", +" if(a(in,1)=='1')\n", +" printf(var(in+2));\n", +" else\n", +" if(a(in,1)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" end\n", +" end\n", +" for in=1:max(size(b(:,1)))\n", +" if(b(in,1)=='1')\n", +" printf(var(in));\n", +" else\n", +" if(b(in,1)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"printf('0');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.3: Reduce_Expressio.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"n=4; //four variable kmap\n", +"k=[0 0 1 0;\n", +" 1 1 1 0;\n", +" 0 1 1 1;\n", +" 0 1 0 0];\n", +"k(:,:,2)=zeros(n,n); //temporary matrix to know whether a element is paired or not\n", +"//declaring notations to display output\n", +"var=['y' 'z' 'w' 'x'];\n", +"p1=['y^z^' 'y''z' 'yz' 'yz'''];\n", +"p2=['w^x^';'w''x';'wx';'wx'''];\n", +"//minimum redundant elements accepted while pairing\n", +"cmn4=1;\n", +"cmn2=1;\n", +"temp=1;\n", +"disp('The minimal ecpression of the given Kmap ');\n", +"disp(k(:,:,1));\n", +"disp('is :');\n", +"disp(' ')\n", +"//16 cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j)~=1)\n", +" temp=0;\n", +" break;\n", +" end\n", +" end\n", +"end\n", +"printf('f=');\n", +"if(temp==1)\n", +" printf('1');\n", +" abort;\n", +"end\n", +"//8 cells\n", +"z1=ones(2,4);\n", +"z2=ones(4,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,:,1);k(t,:,1)];\n", +" if(z==z1)\n", +" k(i,:,2)=[1 1 1 1];\n", +" k(t,:,2)=[1 1 1 1];\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for j=1:n\n", +" if(j==4)\n", +" t=1;\n", +" else\n", +" t=j+1;\n", +" end\n", +" z=[k(:,j,1) k(:,t,1)];\n", +" if(z==z2)\n", +" k(:,j,2)=[1;1;1;1];\n", +" k(:,t,2)=[1;1;1;1];\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" break;\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" printf('+');\n", +" break;\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//2 cells\n", +"z6=[1 1];\n", +"z7=z6';\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z8=[k(i,j,1) k(i,t2,1)];\n", +" z9=[k(i,j,2) k(i,t2,2)];\n", +" no1=number_of(z9,1);\n", +" if(z8==z6 & no1<cmn2)\n", +" if(i==3 & i+j==5)\n", +" ;\n", +" else\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p1(1,i));\n", +" printf('%s''',var(2+in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p1(1,i));\n", +" printf(var(2+in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z10=[k(i,j,1);k(t1,j,1)];\n", +" z11=[k(i,j,2);k(t1,j,2)];\n", +" no2=number_of(z11,1);\n", +" if(z10==z7 & no2<cmn2)\n", +" k(i,j,2)=1;\n", +" k(t1,j,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf(p2(j,1));\n", +" printf('%s''',var(in));\n", +" printf('+');\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(p2(j,1));\n", +" printf(var(in));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//4 cells\n", +"z1=ones(1,4);\n", +"z2=ones(4,1);\n", +"z3=ones(2,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=temp1';\n", +"for t=1:n\n", +" z=k(t,:,1);\n", +" no=number_of(k(t,:,2),1);\n", +" if(z==z1 & no<cmn4)\n", +" k(t,:,2)=z1;\n", +" a=strsplit(temp1(1,t));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for t=1:n\n", +" z=k(:,t,1);\n", +" no=number_of(k(:,t,2),1);\n", +" if(z==z2 & no<cmn4)\n", +" k(:,t,2)=z2;\n", +" a=strsplit(temp2(t,1));\n", +" for in=1:max(size(a))\n", +" if(a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +"end\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==n)\n", +" t1=1;\n", +" else\n", +" t1=i+1;\n", +" end\n", +" if(j==n)\n", +" t2=1;\n", +" else\n", +" t2=j+1;\n", +" end\n", +" z4=[k(i,j,1) k(i,t2,1);k(t1,j,1) k(t1,t2,1)];\n", +" z5=[k(i,j,2) k(i,t2,2);k(t1,j,2) k(t1,t2,2)];\n", +" no=number_of(z5,1);\n", +" if(z4==z3 & no<cmn4)\n", +" k(i,j,2)=1;\n", +" k(i,t2,2)=1;\n", +" k(t1,j,2)=1;\n", +" k(t1,t2,2)=1;\n", +" a=strsplit(temp2(i,1));\n", +" b=strsplit(temp2(t1,1));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp1(1,t2));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"//single cell\n", +"for i=1:n\n", +" for j=1:n\n", +" if(k(i,j,2)==0 & k(i,j,1)==1)\n", +" a=strsplit(temp1(1,j));\n", +" b=strsplit(temp2(i,1));\n", +" for in=1:max(size(a(:,1)))\n", +" if(a(in,1)=='1')\n", +" printf(var(in+2));\n", +" else\n", +" if(a(in,1)=='0')\n", +" printf('%s''',var(2+in));\n", +" end\n", +" end\n", +" end\n", +" for in=1:max(size(b(:,1)))\n", +" if(b(in,1)=='1')\n", +" printf(var(in));\n", +" else\n", +" if(b(in,1)=='0')\n", +" printf('%s''',var(in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"printf('0');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.4: BCD_to_Excess_3_Convertor.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"n=10;\n", +"//coverting decimal numbers into excess 3 values\n", +"for i=0:n-1\n", +" c(i+1,1)=dec21bin(i+3);\n", +"end\n", +"a=c;\n", +"b=zeros(10,4);\n", +"//placing excess 3 outputs in matrix for convenience\n", +"for i=1:n\n", +" j=4;\n", +" while(a(i,1)>=1)\n", +" b(i,j)=round(modulo(a(i,1),10));\n", +" a(i,1)=a(i,1)/10;\n", +" j=j-1;\n", +" end\n", +"end\n", +"//dont care is represented by a 2 since scilab doesnt allow a matrix to contain string and a number.\n", +"for i=n+1:16\n", +" b(i,:)=[2 2 2 2];\n", +"end\n", +"//map of each output variable\n", +"z=[b(1,1) b(5,1) b(13,1) b(9,1);b(2,1) b(6,1) b(14,1) b(10,1);\n", +" b(3,1) b(7,1) b(15,1) b(11,1);b(4,1) b(8,1) b(16,1) b(12,1)];\n", +"y=[b(1,2) b(5,2) b(13,2) b(9,2);b(2,2) b(6,2) b(14,2) b(10,2);\n", +" b(3,2) b(7,2) b(15,2) b(11,2);b(4,2) b(8,2) b(16,2) b(12,2)];\n", +"w=[b(1,3) b(5,3) b(13,3) b(9,3);b(2,3) b(6,3) b(14,3) b(10,3);\n", +" b(3,3) b(7,3) b(15,3) b(11,3);b(4,3) b(8,3) b(16,3) b(12,3)];\n", +"x=[b(1,4) b(5,4) b(13,4) b(9,4);b(2,4) b(6,4) b(14,4) b(10,4);\n", +" b(3,4) b(7,4) b(15,4) b(11,4);b(4,4) b(8,4) b(16,4) b(12,4)];\n", +"donkmap(w,1);\n", +"donkmap(x,2);\n", +"donkmap(y,3);\n", +"donkmap(z,4);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.5: 5_variable_Kmap.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//f=x^y^z+wxz+xy+v^w^yz^\n", +"clc;\n", +"n=4;\n", +"k=[0 0 0 0;\n", +" 1 0 1 1;\n", +" 0 1 1 0;\n", +" 1 1 1 0];\n", +"k(:,:,2)=[0 0 0 0;\n", +" 1 0 1 1;\n", +" 0 1 1 0;\n", +" 0 1 1 0];\n", +"//k=[1 0 0 0;\n", +"// 0 0 0 0;\n", +"// 0 0 0 0;\n", +"// 0 0 1 0];\n", +"//k(:,:,2)=[1 0 0 0;\n", +"// 0 0 0 0;\n", +"// 0 0 0 0;\n", +"// 1 0 0 0];\n", +"k(:,:,3)=zeros(n,n);\n", +"k(:,:,4)=zeros(n,n);\n", +"var=['y' 'z' 'v' 'w' 'x'];\n", +"p1=['y''z''' 'y''z' 'yz' 'yz'''];\n", +"p2=['v''w''x''';'v''w''x';'v''wx';'v''wx''';\n", +"'vw''x''';'vw''x';'vwx';'vwx'''];\n", +"cmn16=9;\n", +"cmn8=5;\n", +"cmn4=3;\n", +"cmn2=2;\n", +"temp=1;\n", +" printf('The minimal ecpression of the given Kmap ');\n", +" disp(k(:,:,1));\n", +" disp(k(:,:,2));\n", +" disp('is :');\n", +"printf('f');\n", +"printf('=');\n", +"//32 cells\n", +"for i=1:n\n", +" for j=1:n\n", +" for l=1:2\n", +" if(k(i,j,l)~=1 & k(i,j,l)~=2)\n", +" temp=0;\n", +" break;\n", +" end\n", +" end\n", +" end\n", +"end\n", +"if(temp==1)\n", +" printf('1');\n", +" abort;\n", +"end\n", +"//16 cells\n", +"//8+8 row cells\n", +"z1=ones(2,4,2);\n", +"z2=ones(4,2,2);\n", +"temp1=['00' '01' '11' '10'];\n", +"temp2=['000' '001' '011' '010' '100' '101' '111' '110'];\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,:,1:2);k(t,:,1:2)];\n", +" z1=[k(i,:,3:4);k(t,:,3:4)];\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn16)\n", +" k(i,:,3:4)=ones(4,2);\n", +" k(t,:,3:4)=ones(4,2);\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" k(i,:,3:4)=ones(1,4,2);\n", +" k(t,:,3:4)=ones(1,4,2);\n", +" end\n", +"end\n", +"//8+8 column cells\n", +"for j=1:n\n", +" if(j==4)\n", +" t=1;\n", +" else\n", +" t=j+1;\n", +" end\n", +" z=[k(:,j,1:2) k(:,t,1:2)];\n", +" z1=[k(:,j,3:4) k(:,t,3:4)];\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn16)\n", +" k(:,j,3:4)=ones(4,2);\n", +" k(:,t,3:4)=ones(4,2);\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,t));\n", +" c=strsplit(temp2(1,j+4));\n", +" d=strsplit(temp2(1,t+4));\n", +" c1=check(a,b,c,d);\n", +" for in=1:max(size(c1))\n", +" if(c1(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c1(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(:,j,3:4)=ones(1,4,2);\n", +" k(:,t,3:4)=ones(1,4,2);\n", +" end\n", +"end\n", +"//4x4 front matrix\n", +"if(number_of(k(:,:,1),0)==0 & number_of(k(:,:,3),1)<cmn16)\n", +" printf(var(3));\n", +" printf('''');\n", +" k(:,:,3)=ones(4,4);\n", +"end\n", +"//4x4 rear matrix\n", +"if(number_of(k(:,:,2),0)==0 & number_of(k(:,:,4),1)<cmn16)\n", +" printf(var(3));\n", +" k(:,:,4)=ones(4,4);\n", +"end\n", +"//8 cells\n", +"//2x2 front and rear cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=k(i,j,1:2);\n", +" z(1,2,:)=k(i,u,1:2);\n", +" z(2,1,:)=k(t,j,1:2);\n", +" z(2,2,:)=k(t,u,1:2);\n", +" z1=k(i,j,3:4);\n", +" z1(1,2,:)=k(i,u,3:4);\n", +" z1(2,1,:)=k(t,j,3:4);\n", +" z1(2,2,:)=k(t,u,3:4);\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn8)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,u));\n", +" c=strsplit(temp2(1,4+j));\n", +" d=strsplit(temp2(1,4+u));\n", +" c1=check(a,b,c,d);\n", +" for in=1:max(size(c1))\n", +" if(c1(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c1(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" k(i,j,3:4)=ones(1,1,2);\n", +" k(i,u,3:4)=ones(1,1,2);\n", +" k(t,j,3:4)=ones(1,1,2);\n", +" k(t,u,3:4)=ones(1,1,2);\n", +" printf('+');\n", +" end\n", +" end\n", +"end\n", +"//1x4 front and rear cells\n", +"for i=1:n\n", +" z=k(i,:,1:2);\n", +" z1=k(i,:,3:4);\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn8)\n", +" printf(p1(i));\n", +" printf('+');\n", +" k(i,:,3:4)=ones(1,4,2);\n", +" end\n", +"end\n", +"//4x1 front and rear cells\n", +"for j=1:n\n", +" z=k(:,j,1:2);\n", +" z1=k(:,j,3:4);\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn8)\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,u));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(:,j,3:4)=ones(1,2,4);\n", +" end\n", +"end\n", +"//2x4 front cells\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=k(i,:,1);\n", +" z(2,:,1)=k(t,:,1);\n", +" z1=k(i,:,3);\n", +" z1(2,:,1)=k(t,:,3);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn8)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" printf('%s''',var(3));\n", +" printf('+');\n", +" k(i,:,3)=ones(1,4);\n", +" k(t,:,3)=ones(1,4);\n", +" end\n", +"end\n", +"//2x4 rear cells\n", +"for i=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=k(i,:,2);\n", +" z(2,:,1)=k(t,:,2);\n", +" z1=k(i,:,4);\n", +" z1(2,:,1)=k(t,:,4);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn8)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" printf(var(3));\n", +" printf('+');\n", +" k(i,:,4)=ones(1,4);\n", +" k(t,:,4)=ones(1,4);\n", +" end\n", +"end\n", +"//4x2 front cells\n", +"for j=1:n\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=k(:,j,1);\n", +" z(:,2,1)=k(:,u,1);\n", +" z1=k(:,j,3);\n", +" z1(:,2,1)=k(:,u,3);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn8)\n", +" a=strsplit(temp2(1,i));\n", +" b=strsplit(temp2(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" printf('%s''',var(3));\n", +" printf('+');\n", +" k(:,j,3)=ones(4,1);\n", +" k(:,u,3)=ones(4,1);\n", +" end\n", +"end\n", +"//4x2 rear cells\n", +"for j=1:n\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=k(:,j,2);\n", +" z(:,2,1)=k(:,u,2);\n", +" z1=k(:,j,4);\n", +" z1(:,2,1)=k(:,u,4);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn8)\n", +" a=strsplit(temp2(1,i));\n", +" b=strsplit(temp2(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(4+in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(4+in));\n", +" end\n", +" end\n", +" end\n", +" printf(var(3));\n", +" printf('+');\n", +" k(:,j,4)=ones(4,1);\n", +" k(:,u,4)=ones(4,1);\n", +" end\n", +"end\n", +"//4 cells\n", +"//1x4 front cells\n", +"for i=1:n\n", +" z=k(i,:,1);\n", +" z1=k(i,:,3);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn4)\n", +" printf(p1(1,i));\n", +" printf('%s''',var(3));\n", +" printf('+');\n", +" k(i,:,3)=ones(1,4);\n", +" end\n", +"end\n", +"//1x4 rear cells\n", +"for i=1:n\n", +" z=k(i,:,2);\n", +" z1=k(i,:,4);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn4)\n", +" printf(p1(1,i));\n", +" printf(var(3));\n", +" printf('+');\n", +" k(i,:,4)=ones(1,4);\n", +" end\n", +"end\n", +"//4x1 front cells\n", +"for j=1:n\n", +" z=k(:,j,1);\n", +" z1=k(:,j,3);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn4)\n", +" printf(p2(j,1));\n", +" printf('+');\n", +" k(:,j,3)=ones(4,1);\n", +" end\n", +"end\n", +"//4x1 rear cells\n", +"for j=1:n\n", +" z=k(:,j,2);\n", +" z1=k(:,j,4);\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn4)\n", +" printf(p2(4+j,1));\n", +" printf('+');\n", +" k(:,j,4)=ones(4,1);\n", +" end\n", +"end\n", +"//2x1 front and rear matrix\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,j,1);k(t,j,1)];\n", +" z(:,:,2)=[k(i,j,2) k(t,j,2)];\n", +" z1=[k(i,j,3);k(t,j,3)];\n", +" z1(:,:,2)=[k(i,j,4) k(t,j,4)];\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn4)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,4+j));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(i,j,3)=1;k(t,j,3)=1;\n", +" k(i,j,4)=1; k(t,j,4)=1;\n", +" end\n", +" end\n", +"end\n", +"//1x2 front and rear matrix\n", +"for i=1:n\n", +" for j=1:n\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=[k(i,j,1) k(i,u,1)];\n", +" z(:,:,2)=[k(i,j,2) k(i,u,2)];\n", +" z1=[k(i,j,3) k(i,u,3)];\n", +" z1(:,:,2)=[k(i,j,4) k(i,u,4)];\n", +" if(noof3(z,0)==0 & noof3(z1,1)<1)\n", +" printf(p1(i));\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,u));\n", +" c=strsplit(temp2(1,4+j));\n", +" d=strsplit(temp2(1,4+j));\n", +" c1=check(a,b,c,d);\n", +" for in=1:max(size(c1))\n", +" if(c1(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c1(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(i,j,3)=1; k(i,u,3)=1;\n", +" k(i,j,4)=1; k(i,u,4)=1;\n", +" end\n", +" end\n", +"end\n", +"//2 cells\n", +"//1x2 front cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=[k(i,j,1) k(i,u,1)];\n", +" z1=[k(i,j,3) k(i,u,3)];\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn2)\n", +" printf(p1(1,i));\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,u));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(i,j,3)=1; k(i,u,3)=1;\n", +" end\n", +" end\n", +"end\n", +"//1x2 rear cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(j==4)\n", +" u=1;\n", +" else\n", +" u=j+1;\n", +" end\n", +" z=[k(i,j,2) k(i,u,2)];\n", +" z1=[k(i,j,4) k(i,u,4)];\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn2)\n", +" printf(p1(1,i));\n", +" a=strsplit(temp2(1,4+j));\n", +" b=strsplit(temp2(1,4+u));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(i,j,4)=1; k(i,u,4)=1;\n", +" end\n", +" end\n", +"end\n", +"//2x1 front cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,j,1);k(t,j,1)];\n", +" z1=[k(i,j,3) k(t,j,3)];\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn2)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" printf(p2(j,1))\n", +" printf('+');\n", +" k(i,j,3)=1; k(i,u,3)=1;\n", +" end\n", +" end\n", +"end\n", +"//2x1 rear cells\n", +"for i=1:n\n", +" for j=1:n\n", +" if(i==4)\n", +" t=1;\n", +" else\n", +" t=i+1;\n", +" end\n", +" z=[k(i,j,2);k(t,j,2)];\n", +" z1=[k(i,j,4) k(t,j,4)];\n", +" if(number_of(z,0)==0 & number_of(z1,1)<cmn2)\n", +" a=strsplit(temp1(1,i));\n", +" b=strsplit(temp1(1,t));\n", +" c=strcmp(a,b);\n", +" for in=1:max(size(c))\n", +" if(c(in)==0 & a(in)=='0')\n", +" printf('%s''',var(in));\n", +" else\n", +" if(c(in)==0 & a(in)=='1')\n", +" printf(var(in));\n", +" end\n", +" end\n", +" end\n", +" printf(p2(4+j,1))\n", +" printf('+');\n", +" k(i,j,4)=1; k(i,u,4)=1;\n", +" end\n", +" end\n", +"end\n", +"//1 cell front and rear matrix\n", +"for i=1:n\n", +" for j=1:n\n", +" z=k(i,j,1:2);\n", +" z1=k(i,j,3:4);\n", +" if(noof3(z,0)==0 & noof3(z1,1)<cmn2)\n", +" printf(p1(1,i));\n", +" a=strsplit(temp2(1,j));\n", +" b=strsplit(temp2(1,4+j));\n", +" c=strcmp(a,b);\n", +" for in=2:max(size(c))\n", +" if(a(in)=='0' & c(in)==0)\n", +" printf('%s''',var(2+in));\n", +" else\n", +" if(a(in)=='1' & c(in)==0)\n", +" printf(var(2+in));\n", +" end\n", +" end\n", +" end\n", +" printf('+');\n", +" k(i,j,3:4)=ones(1,1,2);\n", +" end\n", +" end\n", +"end\n", +"//single cell\n", +"for i=1:n\n", +" for j=1:n\n", +" for z=1:2\n", +" if(k(i,j,z)==1 & k(i,j,z+2)==0)\n", +" printf(p2(j,1));\n", +" printf(p1(1,i));\n", +" printf('+');\n", +" end\n", +" end\n", +" end\n", +"end\n", +"printf('0');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.6: Prime_Implicants.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"z=1;\n", +"//evaluating first expression\n", +"for i=0:1\n", +" for j=0:1\n", +" for k=0:1\n", +" for l=0:1\n", +" f1(z,1)=bitor(bitand(i,j),bitand(k,l));\n", +" z=z+1;\n", +" end\n", +" end\n", +" end\n", +"end\n", +"z=1;\n", +"//evaluating 2nd expression\n", +"for i=0:1\n", +" for j=0:1\n", +" for k=0:1\n", +" for l=0:1\n", +" f2(z,1)=bitand(bitand(i,j),bitcmp(k,1));\n", +" z=z+1;\n", +" end\n", +" end\n", +" end\n", +"end\n", +"//determining whether f covers h or not.\n", +"for i=1:16\n", +" if(f2(i,1)==1)\n", +" if(f2(i,1)==f1(i,1))\n", +" ;\n", +" else\n", +" disp('f doesnt cover h');\n", +" abort;\n", +" end\n", +" end\n", +"end\n", +"disp('f covers h and h implies f');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.7: Prime_Implicants_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('f=x^y+xz+y^z^');\n", +"disp('since x^y is a prime implicant neither x^ nor y alone implies f');\n", +"disp('only x^y are covered by f');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.8: Prime_Implicants_Of_a_Function.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"k=[1 1 0 1;\n", +" 0 1 1 1;\n", +" 0 1 1 0;\n", +" 0 0 0 0];\n", +"disp('The prime implicants of function f');\n", +"karmap(k);\n", +"karmap1(k);" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 4.9: Prime_Implicants_Of_a_Function_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"k=[0 1 1 1;\n", +" 0 1 1 0;\n", +" 0 0 1 0;\n", +" 0 0 1 0];\n", +"disp('The prime implicants of the function f');\n", +"karmap(k);" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/5-Logical_Design.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/5-Logical_Design.ipynb new file mode 100644 index 0000000..78c361c --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/5-Logical_Design.ipynb @@ -0,0 +1,252 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 5: Logical Design" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.1: Odd_Parity_Bit_Generator.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//Takes x input and check whether it is valid logic level or not.\n", +"x=input('x = ');\n", +"while(x~=0 & x~=1)\n", +" disp('enter a valid logical level');\n", +" x=input('x = ');\n", +"end\n", +"//Takes y input and check whether it is valid logic level or not.\n", +"y=input('y = ');\n", +"while(y~=0 & y~=1)\n", +" disp('enter a valid logical level');\n", +" y=input('y = ');\n", +"end\n", +"//Takes z input and check whether it is valid logic level or not.\n", +"z=input('z = ');\n", +"while(z~=0 & z~=1)\n", +" disp('enter a valid logical level');\n", +" z=input('z = ');\n", +"end\n", +"p1=bitand(bitand(bitcmp(x,1),bitcmp(y,1)),z);\n", +"p2=bitand(bitand(bitcmp(x,1),y),bitcmp(z,1));\n", +"p3=bitand(bitand(bitcmp(y,1),x),bitcmp(z,1));\n", +"p4=bitand(bitand(x,y),z);\n", +"p=bitor(bitor(p1,p2),bitor(p3,p4));\n", +"disp(p,'The output of the odd parity generator circuit is');\n", +"disp('p= x^y^z+x^yz^+xy^z^+xyz');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.2: Serial_To_Parallel_converter.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//Takes x input and check whether it is valid logic level or not.\n", +"disp('enter the vaLue of input Line & controL signaLs C1 and C2');\n", +"x=input('x = ');\n", +"while(x~=0 & x~=1)\n", +" disp('enter a vaLid LogicaL LeveL');\n", +" x=input('x = ');1\n", +"end\n", +"//Takes C1 input and check whether it is valid logic level or not.\n", +"C1=input('C1 = ');\n", +"while(C1~=0 & C1~=1)\n", +" disp('enter a vaLid LogicaL LeveL');\n", +" C1=input('C1 = ');\n", +"end\n", +"//Takes C2 input and check whether it is valid logic level or not.\n", +"C2=input('C2 = ');\n", +"while(C2~=0 & C2~=1)\n", +" disp('enter a vaLid LogicaL LeveL');\n", +" C2=input('C2 = ');\n", +"end\n", +"disp('-------OUTPUT-------');\n", +"disp(L1=bitand(bitand(bitcmp(C1,1),bitcmp(C2,1)),x),'L1 = ');\n", +"disp(L2=bitand(bitand(bitcmp(C1,1),C2),x),'L2 = ');\n", +"disp(L3=bitand(bitand(C1,bitcmp(C2,1)),x),'L3 = ');\n", +"disp(L4=bitand(bitand(C1,C2),x),'L4 = ');\n", +"disp('L1=xC1^C2^');\n", +"disp('L2=xC1^C2');\n", +"disp('L3=xC1C2^');\n", +"disp('L4=xC1^C2^');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.3: Transmission_function_for_a_network.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//Takes input and check whether it is valid logic level or not.\n", +"w=input('w = ');\n", +"while(w~=0 & w~=1)\n", +" disp('enter a valid logical level');\n", +" w=input('w = ');\n", +"end\n", +"x=input('x = ');\n", +"while(x~=0 & x~=1)\n", +" disp('enter a valid logical level');\n", +" x=input('x = ');\n", +"end\n", +"y=input('y = ');\n", +"while(y~=0 & y~=1)\n", +" disp('enter a valid logical level');\n", +" y=input('y = ');\n", +"end\n", +"z=input('z = ');\n", +"while(z~=0 & z~=1)\n", +" disp('enter a valid logical level');\n", +" z=input('z = ');\n", +"end\n", +"disp('original network x^[((y^z+z^y)w^)+w+y^+x^z^]');\n", +"disp('x^[w^y^z+w^yz^+w+y^+x^z^]');\n", +"disp('x^[y^(w^z+1)+w^yz^+w+x^z^]');\n", +"disp('x^[y^+w+yz^+x^z^]');\n", +"disp('x^[y^+yz^+w+x^z^]');\n", +"disp('x^[y^+z^+x^z^+w]');\n", +"disp('x^[y^+z^+w]');\n", +"//output of the relay network for the inputs given\n", +"disp(p=bitand(bitcmp(x,1),bitor(bitor(bitcmp(y,1),bitcmp(z,1)),w)),'output = ');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.4: 4_Input_Contact_Network.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//Takes input and check whether it is valid logic level or not.\n", +"w=input('w = ');\n", +"while(w~=0 & w~=1)\n", +" disp('enter a valid logical level');\n", +" w=input('w = ');\n", +"end\n", +"x=input('x = ');\n", +"while(x~=0 & x~=1)\n", +" disp('enter a valid logical level');\n", +" x=input('x = ');\n", +"end\n", +"y=input('y = ');\n", +"while(y~=0 & y~=1)\n", +" disp('enter a valid logical level');\n", +" y=input('y = ');\n", +"end\n", +"z=input('z = ');\n", +"while(z~=0 & z~=1)\n", +" disp('enter a valid logical level');\n", +" z=input('z = ');\n", +"end\n", +"disp('We have 4 relays W,X,Y,Z which takes BCD number as input');\n", +"disp('so the max value value we can get is 1001');\n", +"disp('By drawing the Karnaugh map(consider all terms above 1001 as dont cares ) the minimised expression is');\n", +"disp('T(w,x,y,z)=wz+xyz^+x^yz');\n", +"disp('T(w,x,y,z)=xyz^+x^yz');\n", +"disp('Draw the series parallel realization of T');\n", +"disp('We can identify the redundancy of y contact at the right end');\n", +"disp('which can be removed');\n", +"disp('The cutset realisation of the above minimized series parallel network is');\n", +"disp('T(w,x,y,z)=(w+y)(x+z)(x^+z^)');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.5: Minimal_contact_Network.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Given minimal contact network is T(w,x,y,z)=wxy+wxz+w^x^y^z^+w^x^yz');\n", +"disp('T(w,x,y,z)=wx(y+z)+w^x^(y^z^+yz)');\n", +"disp('Draw the equivalent series parallel circuit of T');\n", +"disp('Interchange the locations of contacts of w^ and x^ and connect the nodes');\n", +"disp('By connecting in the above manner there is no logical effect since the connection path is not at all used');\n", +"disp('now the lower branch of yz+y^z^ can be written as (y+z^)(y^+z) so transfer contacts can be used');\n", +"disp('This parallel connection enables us to combine two parallel z contacts and thus the minimum spring connection is obtained');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/6-Functional_Decomposition_And_Symmetric_Functions.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/6-Functional_Decomposition_And_Symmetric_Functions.ipynb new file mode 100644 index 0000000..4ba57f6 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/6-Functional_Decomposition_And_Symmetric_Functions.ipynb @@ -0,0 +1,177 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 6: Functional Decomposition And Symmetric Functions" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 6.1: Function_Decomposition.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Given function f(w,x,y,z) can be written as follows');\n", +"disp('f(w,x,y,z)=w^x^z^+wx^z+w^yz+wyz^');\n", +"disp('f(w,x,y,z)=((w^z^+wz)x^+(w^z+wz^)y)');\n", +"disp('let Q=w^z^+wz');\n", +"disp('then we can rewrite f as f(w,x,y,z)=Qx^+Q^y');\n", +"disp('f(w,x,y,z)=Qx^+Q^y=F[Q(w,z),x,y]');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 6.3: Muliplicity.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//determines the row and column multiplicity of a mtraix\n", +"//m=input('enter the number of variables in the function=');\n", +"m=4;\n", +"for i=1:m\n", +" for j=1:m\n", +" x(i,j)=0;\n", +" end\n", +"end\n", +"//k='y';\n", +"//disp('Enter the cells index whose values are 1 in the matrix representing your function');\n", +"//while(k~='n')\n", +"// i=input('x index =');\n", +"// j=input('y index =');\n", +"// x(i,j)=1;\n", +"// k=input('If you want to enter more enter y(in quotes) else n(in quotes) :');\n", +"//end\n", +"x=[1 0 1 1;\n", +" 0 0 1 0;\n", +" 0 1 1 1;\n", +" 1 1 0 1];\n", +"l=0;\n", +"//checks every row and find the max no of ones in a row.\n", +"for i=1:m\n", +" k=0;\n", +" for j=1:m\n", +" if(x(i,j)==1)\n", +" k=k+1;\n", +" end\n", +" end\n", +" if(k>l)\n", +" l=k;\n", +" end\n", +"end\n", +"disp(l,'Row multiplicity =');\n", +"l=0;\n", +"//checks every column and find the max no of ones in a column.\n", +"for j=1:m\n", +" k=0;\n", +" for i=1:m\n", +" if(x(i,j)==1)\n", +" k=k+1;\n", +" end\n", +" end\n", +" if(k>l)\n", +" l=k;\n", +" end\n", +"end\n", +"disp(l,'Column multiplicity =');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 6.6: Symmetric.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('f(x,y,z)=x^y^z+xy^z^+x^yz^');\n", +"disp('since interchanging any two variables gives us the same equation');\n", +"disp('for example interchange x and y');\n", +"disp('f(y,x,z)=y^x^z+yx^z^+y^xz^');\n", +"disp('f(x,y,z)=f(y,x,z)');\n", +"disp('So the function f(x,y,z) is symmetric');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 6.7: Symmetric_2.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('f(x1,x2,x3)=x1^x2^x3^+x1x2^x3+x1^x2x3');\n", +"disp('you can check that above equatioin is not symmetric in x1,x2,x3');\n", +"disp('But it is symmetric in x1,x2,x3^');\n", +"disp('let us verify it with interchanging x1 and x3^');\n", +"disp('f(x3^,x2,x1)=x3x2^x1+x3^x2^x1^+x3x2x1^');\n", +"disp('you can identify that f(x1,x2,x3)=f(x3^,x2,x1)');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/7-Threshold_Logic.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/7-Threshold_Logic.ipynb new file mode 100644 index 0000000..9e4aa89 --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/7-Threshold_Logic.ipynb @@ -0,0 +1,252 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 7: Threshold Logic" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.1: weighted_Sum.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"//takes the input and check whether it is valid or not\n", +"x1=input('x1 = ');\n", +"while(x1~=0 & x1~=1)\n", +" disp('enter a valid logical level');\n", +" x1=input('x1 = ');\n", +"end\n", +"x2=input('x2 = ');\n", +"while(x2~=0 & x2~=1)\n", +" disp('enter a valid logical level');\n", +" x2=input('x = ');\n", +"end\n", +"x3=input('x3 = ');\n", +"while(x3~=0 & x3~=1)\n", +" disp('enter a valid logical level');\n", +" x3=input('x3 = ');\n", +"end\n", +"f=-x1+(2*x2)+x3;\n", +"if(f>0.5) then\n", +" f=1;\n", +"else\n", +" f=0;\n", +"end\n", +"disp(f,'output y is');\n", +"m=1;\n", +"//displays the output of the above expression for all the combinations of inputs.\n", +"for x=0:1\n", +" for y=0:1\n", +" for z=0:1\n", +" f1(m,1)=x;\n", +" f1(m,2)=y;\n", +" f2(m,3)=z;\n", +" f1(m,4)=-x+(2*y)+z;\n", +" if(f1(m,4)>0.5) then\n", +" f1(m,5)=1;\n", +" else\n", +" f1(m,5)=0;\n", +" end\n", +" m=m+1;\n", +" end\n", +" end\n", +"end\n", +"disp(' x1 x2 x3 sum y');\n", +"disp(f1)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.2: Inequalities.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"y='y';\n", +"i=1;\n", +"//Takes the equivalent decimal value of the min terms for eg: x^yz=011=3\n", +"while(y=='y')\n", +" disp('enter the minterm of a 3 variable function');\n", +" x(i)=input(': ');\n", +" while(x(i)>7)\n", +" disp('enter a valid minterm');\n", +" end\n", +" disp('press y if you want to enter more min terms else n :');\n", +" y=input('');\n", +" i=i+1;\n", +"end\n", +"a=1;\n", +"//Generating truth table for determining the inequalities\n", +"for i=0:1\n", +" for j=0:1\n", +" for k=0:1\n", +" for z=1:length(x)\n", +" if(x(z)==a-1);\n", +" f(a,4)=1;\n", +" end\n", +" end\n", +" f(a,1)=i;\n", +" f(a,2)=j;\n", +" f(a,3)=k;\n", +" a=a+1;\n", +" end\n", +" end\n", +"end\n", +"//displaying the truth table\n", +"disp(' x1 x2 x3 f');\n", +"disp(f);\n", +"disp('');\n", +"a=1;\n", +"//generating inequalities\n", +"for i=0:1\n", +" for j=0:1\n", +" for k=0:1\n", +" if(f(a,4)==1)\n", +" printf('%3d * w1 + %3d * w2 + %3d * w3>=T',f(a,1),f(a,2),f(a,3))\n", +" disp('')\n", +" else\n", +" printf('%3d * w1 + %3d * w2 + %3d * w3<T',f(a,1),f(a,2),f(a,3))\n", +" disp('')\n", +" end\n", +" a=a+1;\n", +" end\n", +" end\n", +"end\n", +"disp('By solving the above inequalities we can get the values of weights and T');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.3: Unate_Functions.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Given function is f=x1x2^+x2x3^');\n", +"disp('Since x1 has no complemented form in the above function f,f is positive in x1');\n", +"disp('x2 has both complemented and uncomplemented forms in f so f is not unate in x2');\n", +"disp('x3 is only in complemented form so f is negative in x3');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.4: three_cube_representation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('given function is f=x1^x2+x2x3^');\n", +"disp('Since the varibles x1 and x3 are only in their complemented form f is negative and unate in x1 and x3');\n", +"disp('even x2 is only in its uncomplemented form so f is positive in x2');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.5: True_Vertex.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"n=input('Enter the no of input variables :');\n", +"//Input the true minimal vertices \n", +"v=input('Enter the no of minimal true vertices :');\n", +"disp('vertex will be in the form of 101 if it is 3 variable');\n", +"for i=1:v\n", +" printf('Vertex %3d :',i)\n", +" s(i)=input(' ');\n", +"end\n", +"tv=input('enter a vertex which you want find whether true vertex or not');\n", +"//determines whether the vertex is a true or not by comparing it with the true minimal vertices\n", +"for i=1:v\n", +" if(tv>s(i))\n", +" disp('It is a true vertex');\n", +" break;\n", +" else\n", +" if(i==v)\n", +" disp('It is not a true vertex since it is not > than any of the min vertices');\n", +" end\n", +" end\n", +"end" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/8-Reliable_Design_And_Fault_Diagnosis.ipynb b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/8-Reliable_Design_And_Fault_Diagnosis.ipynb new file mode 100644 index 0000000..e3197dc --- /dev/null +++ b/Switching_And_Finite_Automata_Theory_by_Z_Kohavi/8-Reliable_Design_And_Fault_Diagnosis.ipynb @@ -0,0 +1,148 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 8: Reliable Design And Fault Diagnosis" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.1: NOR_Logic_Circuit.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('To find whether h is s-a-0 or not');\n", +"disp('First we have to express f as function of h and x1,x2,x3,x4');\n", +"disp('Simplifying the given logical circuit we obtain the expression of output as');\n", +"disp('f(X,h) = x1x2x3x4 + h(x2x3 + x1^x2^x3^x4^))');\n", +"disp('Here h = x2^x3^');\n", +"disp('let G = x1x2x3x4 & H = h(x2x3 + x1^x2^x3^x4^)');\n", +"disp('Taking derivative on both sides');\n", +"disp('df/dh=G^dH/dh');\n", +"disp('Appllying the formula d[f(X)+g(X)]/dx=f^(X)dg(X)/dx exor g^(X)df(X)/dx exor df(X)/dx.dg(X)/dx');\n", +"disp('df/dh=G^dH/dh=(x1^+x2^+x3^+x4^)(x2x3+x1^x2^x3^x4^)');\n", +"disp('df/dh=x1^x2x3+x2x3x4^+x1^x2^x3^x4^');\n", +"disp('To find tests for h s-a-0 we compute the values for which h(df/dh)=1');\n", +"disp('hdf/dh=x2^x3^(x1^x2x3+x2x3x4^+x1^x2^x3^x4^)');\n", +"disp('hdf/dh=x1^x2^x3^x4^');\n", +"disp('Thus the test set for h s-a-0 is X(0,0,0,0)');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.2: Path_Sensitizing.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('To prove whether there possibiliy of identifing the fault by sensitising just a single path');\n", +"disp('Let us sensitize the path G3 G6 G9');\n", +"disp('This requires G6=1 , G10=0 , G11=0 ,G8=0 ');\n", +"disp('Which inturn requires x2=0 and x3=0 (since G6=1)');\n", +"disp('G10=0 impiles that x4=1 regardless of whether there is a fault or not');\n", +"disp('G11=0 implies G7=1(since x3=0) which in turn implies x4=0');\n", +"disp('Evidently to satisfy both G10=0 and G11=0 we must set conflicting requirements on x4 and thus have a contradiction');\n", +"disp('By symmetry of the circuit it is obvious that an attempt to sensitize the path through G10 will also fail');\n", +"disp('Hence the method of one dimensional path sensitizing fails to generate the test inputs to detect the fault');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.3: Two_level_OR_AND_Network.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('BY following the procedure discussed in Section 8.6');\n", +"disp('we find that {a}={0 or 2 or 3,9,15}');\n", +"disp('and {b}={7,8.11.13.14}');\n", +"disp('Thus the minimal sets of tests for the above network are ');\n", +"disp('{T}={0 or 2 or 3,7,8,9,11,13,14,15}');\n", +"disp('In this case the s-tests and b-tests correspond to s-a-0 and s-a-1 respectively');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.4: Various_errors_Summarized.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"clc;\n", +"clear;\n", +"disp('Various errors associated with some commonly used gates are summarised below');\n", +"disp('A 0-to-1 error in an AND gate with R identical inputs is subcritical');\n", +"disp('since the output depends on the other input so it is subcritical');\n", +"disp('If the same 0-to-1 error is in a OR gate with R identical inputs then it is critical error');\n", +"disp('since an error input struck at 1 will make the output of OR gate to 1 all the time');\n", +"disp('Similarly the critical error of AND gate is subcritical error of OR gate');\n", +"disp('Similarly the error classicfication in various gates is mentioned in Table 8-2')" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |