git.iko.soy/ikoHSE/SolveAvdoshin
on master help sign in
Adjusted the solution output

Now every excercise is represented by a separate public BooleanFunctions method

commitd18c85550009433d2d87e2d8b841e3a5727c1e35 authorIlya Gulkov <isgulkov@edu.hse.ru> dateFri 9 Oct 2015, 21:10 (11 years ago) parentf6bc967
2 files changed+179−162
SolveAvdoshin/BooleanFunctions.cs+143−158 SolveAvdoshin/SolveAvdoshin.cs+36−4
SolveAvdoshin/BooleanFunctions.cs+143−158
@@ -106,34 +106,165 @@ namespace SolveAvdoshin
106106 }
107107 }
108108
109− public static void PrintAllDerivatives(int n)
109+ static readonly BooleanVariable[][] VarLists = new BooleanVariable[][] {
110+ new BooleanVariable[] { BooleanVariable.A, },
111+ new BooleanVariable[] { BooleanVariable.B, },
112+ new BooleanVariable[] { BooleanVariable.C, },
113+ new BooleanVariable[] { BooleanVariable.A, BooleanVariable.B, },
114+ new BooleanVariable[] { BooleanVariable.B, BooleanVariable.C, },
115+ new BooleanVariable[] { BooleanVariable.A, BooleanVariable.C, },
116+ new BooleanVariable[] { BooleanVariable.A, BooleanVariable.B, BooleanVariable.C, },
117+ };
118+
119+ static readonly string[] DerivStrings = new string[] {
120+ "F'_A",
121+ "F'_B",
122+ "F'_C",
123+ "F''_AB",
124+ "F''_BC",
125+ "F''_AC",
126+ "F'''_ABC",
127+ };
128+
129+ static readonly string[] DirDerivStrings = new string[] {
130+ "F'_A",
131+ "F'_B",
132+ "F'_C",
133+ "F'_(A,B)",
134+ "F'_(B,C)",
135+ "F'_(A,C)",
136+ "F'_(A,B,C)",
137+ };
138+
139+ static void PrintJustTruthTable(BooleanFunction f)
140+ {
141+ Console.WriteLine((new BooleanFunction(0x0F)).ToString("A"));
142+ Console.WriteLine((new BooleanFunction(0x33)).ToString("B"));
143+ Console.WriteLine((new BooleanFunction(0x55)).ToString("C"));
144+
145+ Console.WriteLine(f.ToString("F"));
146+ }
147+
148+ public static void PrintDerivatives(int n)
110149 {
111150 BooleanFunction f = new BooleanFunction((byte)n);
112151
113− DerivativePrinting.PrintDerivatives(f);
152+ PrintJustTruthTable(f);
153+
154+ for(int i = 0; i < 7; i++) {
155+ Console.WriteLine(f.Deriv(VarLists[i]).ToString(DerivStrings[i]));
156+ }
114157
115− DerivativePrinting.PrintExpressionsForDerivatives(f, AvdoshinBases[0], AvdoshinVars[0]);
158+ Console.WriteLine();
159+ }
116160
117− DerivativePrinting.Print2DirectionalDerivatives(f);
161+ public static void Print2DirectionalDerivatives(int n)
162+ {
163+ BooleanFunction f = new BooleanFunction((byte)n);
118164
119− DerivativePrinting.PrintExpressionsFor2DirDerivatives(f, AvdoshinBases[0], AvdoshinVars[0]);
165+ PrintJustTruthTable(f);
120166
121− DerivativePrinting.Print3DirectionalDerivative(f);
167+ for(int i = 3; i <= 5; i++) {
168+ Console.WriteLine(f.DirectionalDeriv(VarLists[6]).ToString(DirDerivStrings[i]));
169+ }
122170
123− DerivativePrinting.PrintExpressionFor3DirDerivative(f, AvdoshinBases[0], AvdoshinVars[0]);
171+ Console.WriteLine();
124172 }
125173
126− public static void PrintAllRepresentations(int n)
174+ public static void Print3DirectionalDerivative(int n)
127175 {
128176 BooleanFunction f = new BooleanFunction((byte)n);
129177
130− RepresentationPrinting.PrintMaclauren1XorAnd(f);
178+ PrintJustTruthTable(f);
179+
180+ Console.WriteLine(f.DirectionalDeriv(VarLists[6]).ToString(DirDerivStrings[6]));
181+
182+ Console.WriteLine();
183+ }
131184
132− RepresentationPrinting.PrintTailor1XorAnd(f);
185+ public static void PrintExpressionsForDerivatives(int n)
186+ {
187+ BooleanFunction f = new BooleanFunction((byte)n);
133188
134− RepresentationPrinting.PrintMaclauren0EqOr(f);
189+ for(int i = 0; i < 7; i++) {
190+ Console.WriteLine(DerivStrings[i] + " = " + BooleanExpression.FindMininalExpressionInBasis(
191+ f.Deriv(VarLists[i]).Eval(), AvdoshinBases[0], AvdoshinVars[0]).ToString());
192+ }
135193
136− RepresentationPrinting.PrintTailor0EqOr(f);
194+ Console.WriteLine();
195+ }
196+
197+ public static void PrintExpressionsFor2DirDerivatives(int n)
198+ {
199+ BooleanFunction f = new BooleanFunction((byte)n);
200+
201+ for(int i = 3; i <= 5; i++) {
202+ Console.WriteLine(DirDerivStrings[i] + " = " + BooleanExpression.FindMininalExpressionInBasis(
203+ f.DirectionalDeriv(VarLists[i]).Eval(), AvdoshinBases[0], AvdoshinVars[0]).ToString());
204+ }
205+
206+ Console.WriteLine();
207+ }
208+
209+ public static void PrintExpressionFor3DirDerivative(int n)
210+ {
211+ BooleanFunction f = new BooleanFunction((byte)n);
212+
213+ Console.WriteLine(DirDerivStrings[6] + " = " + BooleanExpression.FindMininalExpressionInBasis(
214+ f.DirectionalDeriv(VarLists[6]).Eval(), AvdoshinBases[0], AvdoshinVars[0]).ToString());
215+
216+ Console.WriteLine();
217+ }
218+
219+ static readonly string[] ReprStrings = new string[] {
220+ "(0,0,0)",
221+ "(0,0,1)",
222+ "(0,1,0)",
223+ "(0,1,1)",
224+ "(1,0,0)",
225+ "(1,0,1)",
226+ "(1,1,0)",
227+ "(1,1,1)",
228+ };
229+
230+ public static void PrintMaclauren1XorAnd(int n)
231+ {
232+ BooleanFunction f = new BooleanFunction((byte)n);
233+
234+ Console.WriteLine("F(A,B,C) = " + f.GetTailorStringXor(0));
235+
236+ Console.WriteLine();
237+ }
238+
239+ public static void PrintTailor1XorAnd(int n)
240+ {
241+ BooleanFunction f = new BooleanFunction((byte)n);
242+
243+ for(int i = 0; i < 8; i++) {
244+ Console.WriteLine(ReprStrings[i] + ": F(A,B,C) = " + f.GetTailorStringXor(i));
245+ }
246+
247+ Console.WriteLine();
248+ }
249+
250+ public static void PrintMaclauren0EqOr(int n)
251+ {
252+ BooleanFunction f = new BooleanFunction((byte)n);
253+
254+ Console.WriteLine("F(A,B,C) = " + f.GetTailorStringEq(7));
255+
256+ Console.WriteLine();
257+ }
258+
259+ public static void PrintTailor0EqOr(int n)
260+ {
261+ BooleanFunction f = new BooleanFunction((byte)n);
262+
263+ for(int i = 0; i < 8; i++) {
264+ Console.WriteLine(ReprStrings[i] + ": F(A,B,C) = " + f.GetTailorStringEq(i));
265+ }
266+
267+ Console.WriteLine();
137268 }
138269
139270 public static void PrintClosedClasses(int n)
@@ -253,152 +384,6 @@ namespace SolveAvdoshin
253384 }
254385 }
255386
256− static class DerivativePrinting
257− {
258− static readonly BooleanVariable[][] VarLists = new BooleanVariable[][] {
259− new BooleanVariable[] { BooleanVariable.A, },
260− new BooleanVariable[] { BooleanVariable.B, },
261− new BooleanVariable[] { BooleanVariable.C, },
262− new BooleanVariable[] { BooleanVariable.A, BooleanVariable.B, },
263− new BooleanVariable[] { BooleanVariable.B, BooleanVariable.C, },
264− new BooleanVariable[] { BooleanVariable.A, BooleanVariable.C, },
265− new BooleanVariable[] { BooleanVariable.A, BooleanVariable.B, BooleanVariable.C, },
266− };
267−
268− static readonly string[] DerivStrings = new string[] {
269− "F'_A",
270− "F'_B",
271− "F'_C",
272− "F''_AB",
273− "F''_BC",
274− "F''_AC",
275− "F'''_ABC",
276− };
277−
278− static readonly string[] DirDerivStrings = new string[] {
279− "F'_A",
280− "F'_B",
281− "F'_C",
282− "F'_(A,B)",
283− "F'_(B,C)",
284− "F'_(A,C)",
285− "F'_(A,B,C)",
286− };
287−
288− public static void PrintJustTruthTable(BooleanFunction f)
289− {
290− Console.WriteLine((new BooleanFunction(0x0F)).ToString("A"));
291− Console.WriteLine((new BooleanFunction(0x33)).ToString("B"));
292− Console.WriteLine((new BooleanFunction(0x55)).ToString("C"));
293−
294− Console.WriteLine(f.ToString("F"));
295− }
296−
297− public static void PrintDerivatives(BooleanFunction f)
298− {
299− PrintJustTruthTable(f);
300−
301− for(int i = 0; i < 7; i++) {
302− Console.WriteLine(f.Deriv(VarLists[i]).ToString(DerivStrings[i]));
303− }
304−
305− Console.WriteLine();
306− }
307−
308− public static void Print2DirectionalDerivatives(BooleanFunction f)
309− {
310− PrintJustTruthTable(f);
311−
312− for(int i = 3; i <= 5; i++) {
313− Console.WriteLine(f.DirectionalDeriv(VarLists[6]).ToString(DirDerivStrings[i]));
314− }
315−
316− Console.WriteLine();
317− }
318−
319− public static void Print3DirectionalDerivative(BooleanFunction f)
320− {
321− PrintJustTruthTable(f);
322−
323− Console.WriteLine(f.DirectionalDeriv(VarLists[6]).ToString(DirDerivStrings[6]));
324−
325− Console.WriteLine();
326− }
327−
328− public static void PrintExpressionsForDerivatives(BooleanFunction f, BooleanOperation[] ops, BooleanVariable[] vars)
329− {
330− for(int i = 0; i < 7; i++) {
331− Console.WriteLine(DerivStrings[i] + " = " + BooleanExpression.FindMininalExpressionInBasis(
332− f.Deriv(VarLists[i]).Eval(), ops, vars).ToString());
333− }
334−
335− Console.WriteLine();
336− }
337−
338− public static void PrintExpressionsFor2DirDerivatives(BooleanFunction f, BooleanOperation[] ops, BooleanVariable[] vars)
339− {
340− for(int i = 3; i <= 5; i++) {
341− Console.WriteLine(DirDerivStrings[i] + " = " + BooleanExpression.FindMininalExpressionInBasis(f.DirectionalDeriv(VarLists[i]).Eval(), ops, vars).ToString());
342− }
343−
344− Console.WriteLine();
345− }
346−
347− public static void PrintExpressionFor3DirDerivative(BooleanFunction f, BooleanOperation[] ops, BooleanVariable[] vars)
348− {
349− Console.WriteLine(DirDerivStrings[6] + " = " + BooleanExpression.FindMininalExpressionInBasis(
350− f.DirectionalDeriv(VarLists[6]).Eval(), ops, vars).ToString());
351−
352− Console.WriteLine();
353− }
354− }
355−
356− static class RepresentationPrinting
357− {
358− static readonly string[] ReprStrings = new string[] {
359− "(0,0,0)",
360− "(0,0,1)",
361− "(0,1,0)",
362− "(0,1,1)",
363− "(1,0,0)",
364− "(1,0,1)",
365− "(1,1,0)",
366− "(1,1,1)",
367− };
368−
369− public static void PrintMaclauren1XorAnd(BooleanFunction f)
370− {
371− Console.WriteLine("F(A,B,C) = " + f.GetTailorStringXor(0));
372−
373− Console.WriteLine();
374− }
375−
376− public static void PrintTailor1XorAnd(BooleanFunction f)
377− {
378− for(int i = 0; i < 8; i++) {
379− Console.WriteLine(ReprStrings[i] + ": F(A,B,C) = " + f.GetTailorStringXor(i));
380− }
381−
382− Console.WriteLine();
383− }
384−
385− public static void PrintMaclauren0EqOr(BooleanFunction f)
386− {
387− Console.WriteLine("F(A,B,C) = " + f.GetTailorStringEq(7));
388−
389− Console.WriteLine();
390− }
391−
392− public static void PrintTailor0EqOr(BooleanFunction f)
393− {
394− for(int i = 0; i < 8; i++) {
395− Console.WriteLine(ReprStrings[i] + ": F(A,B,C) = " + f.GetTailorStringEq(i));
396− }
397−
398− Console.WriteLine();
399− }
400− }
401−
402387 class BooleanFunction
403388 {
404389 byte TruthTable;
SolveAvdoshin/SolveAvdoshin.cs+36−4
@@ -106,13 +106,45 @@ namespace SolveAvdoshin
106106
107107 BooleanFunctions.PrintMinimaInAvdoshinBases(answer);
108108
109− Console.WriteLine("\n\n4-9.\n");
109+ Console.WriteLine("\n\n4.\n");
110110
111− BooleanFunctions.PrintAllDerivatives(answer);
111+ BooleanFunctions.PrintDerivatives(answer);
112112
113− Console.WriteLine("\n10-13.\n");
113+ Console.WriteLine("\n5.\n");
114114
115− BooleanFunctions.PrintAllRepresentations(answer);
115+ BooleanFunctions.PrintExpressionsForDerivatives(answer);
116+
117+ Console.WriteLine("\n6.\n");
118+
119+ BooleanFunctions.Print2DirectionalDerivatives(answer);
120+
121+ Console.WriteLine("\n7.\n");
122+
123+ BooleanFunctions.PrintExpressionsFor2DirDerivatives(answer);
124+
125+ Console.WriteLine("\n8.\n");
126+
127+ BooleanFunctions.Print3DirectionalDerivative(answer);
128+
129+ Console.WriteLine("\n9.\n");
130+
131+ BooleanFunctions.PrintExpressionFor3DirDerivative(answer);
132+
133+ Console.WriteLine("\n10.\n");
134+
135+ BooleanFunctions.PrintMaclauren1XorAnd(answer);
136+
137+ Console.WriteLine("\n11.\n");
138+
139+ BooleanFunctions.PrintTailor1XorAnd(answer);
140+
141+ Console.WriteLine("\n12.\n");
142+
143+ BooleanFunctions.PrintMaclauren0EqOr(answer);
144+
145+ Console.WriteLine("\n13.\n");
146+
147+ BooleanFunctions.PrintTailor0EqOr(answer);
116148
117149 Console.WriteLine("\n14.\n");
118150