ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
primes.c
Go to the documentation of this file.
1/*
2 * Revision Control Information
3 *
4 * $Source$
5 * $Author$
6 * $Revision$
7 * $Date$
8 *
9 */
10#include "espresso.h"
11
13
14
15static bool primes_consensus_special_cases();
16static pcover primes_consensus_merge();
17static pcover and_with_cofactor();
18
19
20/* primes_consensus -- generate primes using consensus */
22pcube *T; /* T will be disposed of */
23{
24 register pcube cl, cr;
25 register int best;
26 pcover Tnew, Tl, Tr;
27
28 if (primes_consensus_special_cases(T, &Tnew) == MAYBE) {
29 cl = new_cube();
30 cr = new_cube();
31 best = binate_split_select(T, cl, cr, COMPL);
32
33 Tl = primes_consensus(scofactor(T, cl, best));
34 Tr = primes_consensus(scofactor(T, cr, best));
35 Tnew = primes_consensus_merge(Tl, Tr, cl, cr);
36
37 free_cube(cl);
38 free_cube(cr);
40 }
41
42 return Tnew;
43}
44
45static bool
46primes_consensus_special_cases(T, Tnew)
47pcube *T; /* will be disposed if answer is determined */
48pcover *Tnew; /* returned only if answer determined */
49{
50 register pcube *T1, p, ceil, cof=T[0];
51 pcube last;
52 pcover A;
53
54 /* Check for no cubes in the cover */
55 if (T[2] == NULL) {
56 *Tnew = new_cover(0);
58 return TRUE;
59 }
60
61 /* Check for only a single cube in the cover */
62 if (T[3] == NULL) {
63 *Tnew = sf_addset(new_cover(1), set_or(cof, cof, T[2]));
65 return TRUE;
66 }
67
68 /* Check for a row of all 1's (implies function is a tautology) */
69 for(T1 = T+2; (p = *T1++) != NULL; ) {
70 if (full_row(p, cof)) {
71 *Tnew = sf_addset(new_cover(1), cube.fullset);
73 return TRUE;
74 }
75 }
76
77 /* Check for a column of all 0's which can be factored out */
78 ceil = set_save(cof);
79 for(T1 = T+2; (p = *T1++) != NULL; ) {
80 INLINEset_or(ceil, ceil, p);
81 }
82 if (! setp_equal(ceil, cube.fullset)) {
83 p = new_cube();
84 (void) set_diff(p, cube.fullset, ceil);
85 (void) set_or(cof, cof, p);
86 free_cube(p);
87
88 A = primes_consensus(T);
89 foreach_set(A, last, p) {
90 INLINEset_and(p, p, ceil);
91 }
92 *Tnew = A;
93 set_free(ceil);
94 return TRUE;
95 }
96 set_free(ceil);
97
98 /* Collect column counts, determine unate variables, etc. */
100
101 /* If single active variable not factored out above, then tautology ! */
102 if (cdata.vars_active == 1) {
103 *Tnew = sf_addset(new_cover(1), cube.fullset);
104 free_cubelist(T);
105 return TRUE;
106
107 /* Check for unate cover */
108 } else if (cdata.vars_unate == cdata.vars_active) {
109 A = cubeunlist(T);
110 *Tnew = sf_contain(A);
111 free_cubelist(T);
112 return TRUE;
113
114 /* Not much we can do about it */
115 } else {
116 return MAYBE;
117 }
118}
119
120static pcover
121primes_consensus_merge(Tl, Tr, cl, cr)
122pcover Tl, Tr;
123pcube cl, cr;
124{
125 register pcube pl, pr, lastl, lastr, pt;
126 pcover T, Tsave;
127
128 Tl = and_with_cofactor(Tl, cl);
129 Tr = and_with_cofactor(Tr, cr);
130
131 T = sf_new(500, Tl->sf_size);
132 pt = T->data;
133 Tsave = sf_contain(sf_join(Tl, Tr));
134
135 foreach_set(Tl, lastl, pl) {
136 foreach_set(Tr, lastr, pr) {
137 if (cdist01(pl, pr) == 1) {
138 consensus(pt, pl, pr);
139 if (++T->count >= T->capacity) {
140 Tsave = sf_union(Tsave, sf_contain(T));
141 T = sf_new(500, Tl->sf_size);
142 pt = T->data;
143 } else {
144 pt += T->wsize;
145 }
146 }
147 }
148 }
149 free_cover(Tl);
150 free_cover(Tr);
151
152 Tsave = sf_union(Tsave, sf_contain(T));
153 return Tsave;
154}
155
156
157static pcover
158and_with_cofactor(A, cof)
160register pset cof;
161{
162 register pset last, p;
163
164 foreach_set(A, last, p) {
165 INLINEset_and(p, p, cof);
166 if (cdist(p, cube.fullset) > 0) {
167 RESET(p, ACTIVE);
168 } else {
169 SET(p, ACTIVE);
170 }
171 }
172 return sf_inactive(A);
173}
175
#define TRUE
Definition abcBm.c:38
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define pcover
Definition espresso.h:264
pset_family sf_addset()
#define new_cube()
Definition espresso.h:262
bool full_row()
#define set_save(r)
Definition espresso.h:166
#define INLINEset_or(r, a, b)
Definition espresso.h:205
pset_family sf_inactive()
pcube * scofactor()
#define COMPL
Definition espresso.h:351
#define set_free(r)
Definition espresso.h:167
pset_family sf_new()
#define ACTIVE
Definition espresso.h:129
void consensus()
pset_family sf_contain()
pcover cubeunlist()
void massive_count()
#define pcube
Definition espresso.h:261
ABC_NAMESPACE_HEADER_END int binate_split_select()
#define free_cover(r)
Definition espresso.h:266
pset set_diff()
pset_family sf_union()
#define free_cube(r)
Definition espresso.h:263
struct set_family * pset_family
#define foreach_set(R, last, p)
Definition espresso.h:135
#define SET(set, flag)
Definition espresso.h:122
#define INLINEset_and(r, a, b)
Definition espresso.h:202
int cdist()
#define RESET(set, flag)
Definition espresso.h:123
unsigned int * pset
Definition espresso.h:73
int cdist01()
pset set_or()
bool setp_equal()
pset_family sf_join()
#define free_cubelist(T)
Definition espresso.h:267
#define MAYBE
Definition espresso.h:257
pcover primes_consensus()
#define new_cover(i)
Definition espresso.h:265
Cube * p
Definition exorList.c:222
Definition exor.h:123