git.iko.soy/ikoHSE/SolveAvdoshin
on master help sign in
Post classes (ex. 14)
commitf6bc96776773f5f60f671679a8860b42b0dac77d authorIlya Gulkov <ifranked@gmail.com> dateThu 8 Oct 2015, 01:19 (11 years ago) parentdc097ec
2 files changed+57−24
SolveAvdoshin/BooleanFunctions.cs+53−24 SolveAvdoshin/SolveAvdoshin.cs+4
SolveAvdoshin/BooleanFunctions.cs+53−24
@@ -140,34 +140,55 @@ namespace SolveAvdoshin
140140 {
141141 BooleanFunction f = new BooleanFunction((byte)n);
142142
143+ ClosedClassPrinting.PrintConservationZero(f);
143144
145+ ClosedClassPrinting.PrintConservationOne(f);
146+
147+ ClosedClassPrinting.PrintSelfDuality(f);
148+
149+ ClosedClassPrinting.PrintMonotony(f);
150+
151+ ClosedClassPrinting.PrintLinearity(f);
144152 }
145153 }
146154
147− static class ClosedClassChecking
155+ static class ClosedClassPrinting
148156 {
149− public static bool CheckConservationZero(BooleanFunction f)
157+ public static void PrintConservationZero(BooleanFunction f)
150158 {
151− return ((f.Eval() >> 7) & 1) == 0;
159+ if(f.EvalAt(0) == 0) {
160+ Console.WriteLine("F ∈ T_0, т.к. F(0,0,0) = 0");
161+ }
162+ else {
163+ Console.WriteLine("F ∉ T_0, т.к. F(0,0,0) = 1");
164+ }
152165 }
153166
154− public static bool CheckConservationOne(BooleanFunction f)
167+ public static void PrintConservationOne(BooleanFunction f)
155168 {
156− return (f.Eval() & 1) == 1;
169+ if(f.EvalAt(7) == 1) {
170+ Console.WriteLine("F ∈ T_1, т.к. F(1,1,1) = 1");
171+ }
172+ else {
173+ Console.WriteLine("F ∉ T_1, т.к. F(1,1,1) = 0");
174+ }
157175 }
158176
159− public static bool CheckSelfDuality(BooleanFunction f)
177+ static string PointAsString(int a)
160178 {
161− bool res = true;
179+ return ((a >> 2) & 1) + "," + ((a >> 1) & 1) + "," + (a & 1);
180+ }
162181
182+ public static void PrintSelfDuality(BooleanFunction f)
183+ {
163184 for(int i = 0; i < 8; i++) {
164− if(((f.Eval() >> i) & 1) == ((f.Eval() >> (7 - i)) & 1)) {
165− res = false;
166− break;
185+ if(f.EvalAt(i) == f.EvalAt(7 - i)) {
186+ Console.WriteLine("F ∉ T_*, т.к. F({0}) = F({1}) = {2}", PointAsString(i), PointAsString(7 - i), f.EvalAt(i));
187+ return;
167188 }
168189 }
169190
170− return res;
191+ Console.WriteLine("F ∈ T_*, т.к. я на всех наборах проверял, честно!");
171192 }
172193
173194 static bool AreAdjacent(int a, int b)
@@ -188,7 +209,7 @@ namespace SolveAvdoshin
188209 return res;
189210 }
190211
191− static bool IsGreatherThan(int a, int b)
212+ static bool IsLessThan(int a, int b)
192213 {
193214 int onesA = 0, onesB = 0;
194215
@@ -197,30 +218,38 @@ namespace SolveAvdoshin
197218 onesB += (b >> i) & 1;
198219 }
199220
200− return onesA > onesB;
221+ return onesA < onesB;
201222 }
202223
203− public static bool CheckMonotony(BooleanFunction f)
224+ public static void PrintMonotony(BooleanFunction f)
204225 {
205− bool res = true;
206−
207226 for(int i = 0; i < 8; i++) {
208227 for(int j = 0; j < 8; j++) {
209− if(AreAdjacent(i, j) && IsGreatherThan(i, j)) {
210− if(f.EvalAt(i) < f.EvalAt(j)) {
211− res = false;
212− break;
213− }
228+ if(!AreAdjacent(i, j) || !IsLessThan(i, j))
229+ continue;
230+
231+ if(f.EvalAt(i) > f.EvalAt(j)) {
232+ Console.WriteLine("F ∉ T_<=, т.к. F({0}) > F({1})", PointAsString(i), PointAsString(j));
233+ return;
214234 }
215235 }
216236 }
217237
218− return res;
238+ Console.WriteLine("F ∈ T_<=, т.к. я на всех наборах проверял, честно!");
219239 }
220240
221− public static bool CheckLinearity(BooleanFunction f)
241+ public static void PrintLinearity(BooleanFunction f)
222242 {
223−
243+ string zhegalkinRep = f.GetTailorStringXor(0);
244+
245+ foreach(string s in new string[] { "AB", "BC", "AC", "ABC", }) {
246+ if(zhegalkinRep.Contains(s)) {
247+ Console.WriteLine("F ∉ T_L, т.к. F(A,B,C) = " + zhegalkinRep);
248+ return;
249+ }
250+ }
251+
252+ Console.WriteLine("F ∈ T_L, т.к. F(A,B,C) = " + zhegalkinRep);
224253 }
225254 }
226255
SolveAvdoshin/SolveAvdoshin.cs+4
@@ -113,6 +113,10 @@ namespace SolveAvdoshin
113113 Console.WriteLine("\n10-13.\n");
114114
115115 BooleanFunctions.PrintAllRepresentations(answer);
116+
117+ Console.WriteLine("\n14.\n");
118+
119+ BooleanFunctions.PrintClosedClasses(answer);
116120 }
117121 catch(FormatException e) {
118122 Console.WriteLine("Osheebka: " + e.Message);