1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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
}
|