git.iko.soy/ikoHSE/SolveAvdoshin
on master help sign in
Implemented AllExpressions()
commit7f59cd0452a19d182fd3ab46c13e7d63d0d7c11b authorIlya Gulkov <ifranked@gmail.com> dateTue 29 Sep 2015, 19:16 (11 years ago) parent721b4cd
3 files changed+76−9
SolveAvdoshin/BooleanFunctions.cs+44−9 SolveAvdoshin/Combinatorics.cs+31 SolveAvdoshin/SolveAvdoshin.csproj+1
SolveAvdoshin/BooleanFunctions.cs+44−9
@@ -21,10 +21,25 @@ namespace SolveAvdoshin
2121//
2222// PrintDerivatives(new BooleanFunction(26));
2323
24− foreach(var t in BooleanExpression.AllTrees(3)) {
25− t.SetIthVar(0, BooleanVariable.B);
26− t.setIthOp(0, BooleanOperation.Xor);
27− Console.WriteLine(t.ToString());
24+// foreach(var t in BooleanExpression.AllTrees(3)) {
25+// t.SetIthVar(0, BooleanVariable.B);
26+// t.setIthOp(0, BooleanOperation.Xor);
27+// Console.WriteLine(t.ToString());
28+// }
29+
30+// foreach(var v in Combinatorics.AllNTuples(new BooleanOperation[] { BooleanOperation.And,
31+// BooleanOperation.Or }, 3)) {
32+// foreach(var b in v) {
33+// Console.Write("{0} ", b);
34+// }
35+// Console.WriteLine();
36+// }
37+
38+ BooleanOperation[] ops = { BooleanOperation.And, BooleanOperation.Or };
39+ BooleanVariable[] vars = { BooleanVariable.A, BooleanVariable.B, BooleanVariable.C };
40+
41+ foreach(var v in BooleanExpression.AllExpressions(3, ops, vars)) {
42+ Console.WriteLine(v.ToString());
2843 }
2944 }
3045 }
@@ -128,6 +143,17 @@ namespace SolveAvdoshin
128143
129144 return ex;
130145 }
146+
147+ public BooleanExpression MininalExpressionInBasis()
148+ {
149+ throw new NotImplementedException();
150+
151+// for(int i = 2; i < 15; i++) {
152+// foreach(var ex in BooleanExpression.AllExpressions(i)) {
153+//
154+// }
155+// }
156+ }
131157 }
132158
133159 enum BooleanOperation { Zero, NOR, NotBImp, NotA, NotImp, NotB, Xor, NAND, And, Eq, B, Imp, A, BImp, Or, One };
@@ -160,12 +186,21 @@ namespace SolveAvdoshin
160186 public static IEnumerable<BooleanExpression> AllExpressions(int size, BooleanOperation[] ops,
161187 BooleanVariable[] vars)
162188 {
163− throw new NotImplementedException();
164− }
189+ foreach(var ex in AllTrees(size)) {
190+ foreach(var opList in Combinatorics.AllNTuples(ops, size)) {
191+ foreach(var varList in Combinatorics.AllNTuples(vars, size + 1)) {
192+ for(int i = 0; i < size; i++) {
193+ ex.setIthOp(i, opList[i]);
194+ }
165195
166− public BooleanExpression FindMininalInBasis()
167− {
168− throw new NotImplementedException();
196+ for(int i = 0; i < size + 1; i++) {
197+ ex.SetIthVar(i, varList[i]);
198+ }
199+
200+ yield return ex;
201+ }
202+ }
203+ }
169204 }
170205 }
171206
SolveAvdoshin/Combinatorics.csnew file+31
@@ -0,0 +1,31 @@
1+using System;
2+using System.Collections.Generic;
3+
4+namespace SolveAvdoshin
5+{
6+ public static class Combinatorics
7+ {
8+ public static IEnumerable<T[]> AllNTuples<T>(T[] items, int size)
9+ {
10+ if(size == 0) {
11+ yield return new T[] { };
12+ }
13+ else {
14+ foreach(var tuple in AllNTuples<T>(items, size - 1)) {
15+ foreach(var item in items) {
16+ T[] newTuple = new T[tuple.Length + 1];
17+
18+ newTuple[0] = item;
19+ tuple.CopyTo(newTuple, 1);
20+
21+ yield return newTuple;
22+
23+ }
24+ }
25+ }
26+
27+
28+ }
29+ }
30+}
31+
SolveAvdoshin/SolveAvdoshin.csproj+1
@@ -37,6 +37,7 @@
3737 <Compile Include="AndXorEquation.cs" />
3838 <Compile Include="SolveAvdoshin.cs" />
3939 <Compile Include="BooleanFunctions.cs" />
40+ <Compile Include="Combinatorics.cs" />
4041 </ItemGroup>
4142 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4243</Project>