[9844] | 1 | PROBLEM Multiplexer
|
---|
| 2 |
|
---|
| 3 | NONTERMINALS
|
---|
| 4 | Expr<<bool[] d, out bool o>>.
|
---|
| 5 | AND<<bool[] d, out bool o>>.
|
---|
| 6 | OR<<bool[] d, out bool o>>.
|
---|
| 7 | NOT<<bool[] d, out bool o>>.
|
---|
| 8 | IF<<bool[] d, out bool o>>.
|
---|
| 9 |
|
---|
| 10 | TERMINALS
|
---|
| 11 | A0. A1. A2. D0. D1. D2. D3. D4. D5. D6. D7.
|
---|
| 12 |
|
---|
| 13 | RULES
|
---|
| 14 | Expr<<bool[] d, out bool o>> =
|
---|
| 15 | AND<<d, out o>>
|
---|
| 16 | | OR<<d, out o>>
|
---|
| 17 | | NOT<<d, out o>>
|
---|
| 18 | | IF<<d, out o>>
|
---|
| 19 | | A0 SEM<< o = d[0]; >>
|
---|
| 20 | | A1 SEM<< o = d[1]; >>
|
---|
| 21 | | A2 SEM<< o = d[2]; >>
|
---|
| 22 | | D0 SEM<< o = d[3]; >>
|
---|
| 23 | | D1 SEM<< o = d[4]; >>
|
---|
| 24 | | D2 SEM<< o = d[5]; >>
|
---|
| 25 | | D3 SEM<< o = d[6]; >>
|
---|
| 26 | | D4 SEM<< o = d[7]; >>
|
---|
| 27 | | D5 SEM<< o = d[8]; >>
|
---|
| 28 | | D6 SEM<< o = d[9]; >>
|
---|
| 29 | | D7 SEM<< o = d[10]; >>
|
---|
| 30 | .
|
---|
| 31 |
|
---|
| 32 | AND<<bool[] d, out bool o>> = LOCAL << bool o1, o2; >>
|
---|
| 33 | Expr<<d, out o1>> Expr<<d, out o2>> SEM << o = o1 & o2; >>
|
---|
| 34 | .
|
---|
| 35 |
|
---|
| 36 | OR<<bool[] d, out bool o>> = LOCAL << bool o1, o2; >>
|
---|
| 37 | Expr<<d, out o1>> Expr<<d, out o2>> SEM << o = o1 | o2; >>
|
---|
| 38 | .
|
---|
| 39 |
|
---|
| 40 | NOT<<bool[] d, out bool o>> =
|
---|
| 41 | Expr<<d, out o>> SEM << o = !o; >>
|
---|
| 42 | .
|
---|
| 43 |
|
---|
| 44 | IF<<bool[] d, out bool o>> = LOCAL << bool pred; >>
|
---|
| 45 | Expr<<d, out pred>> SEM << if(pred) { >>
|
---|
| 46 | Expr<<d, out o>> SEM << } else { >>
|
---|
| 47 | Expr<<d, out o>> SEM << } >>
|
---|
| 48 | .
|
---|
| 49 |
|
---|
| 50 | MINIMIZE
|
---|
| 51 | <<
|
---|
| 52 | int N = 11;
|
---|
| 53 | bool[] d = new bool[N];
|
---|
| 54 | int mistakes = 0;
|
---|
| 55 | for(int i = 0; i < Math.Pow(2, N); i++) {
|
---|
| 56 | // generate bit-vector and count number of 1-bits
|
---|
| 57 | int x = i;
|
---|
| 58 | for(int j = 0; j < N; j++) {
|
---|
| 59 | d[N - j - 1] = ((x % 2) == 1);
|
---|
| 60 | x = (x / 2);
|
---|
| 61 | }
|
---|
| 62 | bool target = d[3 + (d[0] ? 1:0) + 2 * (d[1] ? 1:0) + 4 * (d[2] ? 1:0)];
|
---|
| 63 |
|
---|
| 64 | // apply model
|
---|
| 65 | bool p;
|
---|
| 66 | Expr(d, out p);
|
---|
| 67 |
|
---|
| 68 | if(p != target) mistakes++;
|
---|
| 69 | }
|
---|
| 70 | return mistakes;
|
---|
| 71 | >>
|
---|
| 72 | END Multiplexer.
|
---|