cadical 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +26 -0
  3. data/README.md +101 -0
  4. data/ext/cadical/cadical/LICENSE +28 -0
  5. data/ext/cadical/cadical/README.md +65 -0
  6. data/ext/cadical/cadical/VERSION +1 -0
  7. data/ext/cadical/cadical/src/analyze.cpp +1360 -0
  8. data/ext/cadical/cadical/src/arena.cpp +30 -0
  9. data/ext/cadical/cadical/src/arena.hpp +105 -0
  10. data/ext/cadical/cadical/src/assume.cpp +616 -0
  11. data/ext/cadical/cadical/src/averages.cpp +34 -0
  12. data/ext/cadical/cadical/src/averages.hpp +37 -0
  13. data/ext/cadical/cadical/src/backbone.cpp +631 -0
  14. data/ext/cadical/cadical/src/backtrack.cpp +177 -0
  15. data/ext/cadical/cadical/src/backward.cpp +231 -0
  16. data/ext/cadical/cadical/src/bins.cpp +22 -0
  17. data/ext/cadical/cadical/src/bins.hpp +22 -0
  18. data/ext/cadical/cadical/src/block.cpp +824 -0
  19. data/ext/cadical/cadical/src/block.hpp +37 -0
  20. data/ext/cadical/cadical/src/cadical.cpp +1026 -0
  21. data/ext/cadical/cadical/src/cadical.hpp +1419 -0
  22. data/ext/cadical/cadical/src/ccadical.cpp +208 -0
  23. data/ext/cadical/cadical/src/ccadical.h +74 -0
  24. data/ext/cadical/cadical/src/checker.cpp +649 -0
  25. data/ext/cadical/cadical/src/checker.hpp +173 -0
  26. data/ext/cadical/cadical/src/clause.cpp +689 -0
  27. data/ext/cadical/cadical/src/clause.hpp +190 -0
  28. data/ext/cadical/cadical/src/collect.cpp +545 -0
  29. data/ext/cadical/cadical/src/compact.cpp +550 -0
  30. data/ext/cadical/cadical/src/condition.cpp +940 -0
  31. data/ext/cadical/cadical/src/config.cpp +101 -0
  32. data/ext/cadical/cadical/src/config.hpp +20 -0
  33. data/ext/cadical/cadical/src/congruence.cpp +7880 -0
  34. data/ext/cadical/cadical/src/congruence.hpp +757 -0
  35. data/ext/cadical/cadical/src/constrain.cpp +64 -0
  36. data/ext/cadical/cadical/src/contract.cpp +27 -0
  37. data/ext/cadical/cadical/src/contract.hpp +139 -0
  38. data/ext/cadical/cadical/src/cover.cpp +704 -0
  39. data/ext/cadical/cadical/src/cover.hpp +34 -0
  40. data/ext/cadical/cadical/src/decide.cpp +347 -0
  41. data/ext/cadical/cadical/src/decompose.cpp +738 -0
  42. data/ext/cadical/cadical/src/decompose.hpp +23 -0
  43. data/ext/cadical/cadical/src/deduplicate.cpp +275 -0
  44. data/ext/cadical/cadical/src/definition.cpp +283 -0
  45. data/ext/cadical/cadical/src/delay.hpp +38 -0
  46. data/ext/cadical/cadical/src/drattracer.cpp +153 -0
  47. data/ext/cadical/cadical/src/drattracer.hpp +55 -0
  48. data/ext/cadical/cadical/src/elim.cpp +1171 -0
  49. data/ext/cadical/cadical/src/elim.hpp +53 -0
  50. data/ext/cadical/cadical/src/elimfast.cpp +570 -0
  51. data/ext/cadical/cadical/src/ema.cpp +95 -0
  52. data/ext/cadical/cadical/src/ema.hpp +68 -0
  53. data/ext/cadical/cadical/src/extend.cpp +289 -0
  54. data/ext/cadical/cadical/src/external.cpp +1034 -0
  55. data/ext/cadical/cadical/src/external.hpp +487 -0
  56. data/ext/cadical/cadical/src/external_propagate.cpp +1316 -0
  57. data/ext/cadical/cadical/src/factor.cpp +1011 -0
  58. data/ext/cadical/cadical/src/factor.hpp +54 -0
  59. data/ext/cadical/cadical/src/file.cpp +506 -0
  60. data/ext/cadical/cadical/src/file.hpp +210 -0
  61. data/ext/cadical/cadical/src/flags.cpp +135 -0
  62. data/ext/cadical/cadical/src/flags.hpp +93 -0
  63. data/ext/cadical/cadical/src/flip.cpp +269 -0
  64. data/ext/cadical/cadical/src/format.cpp +89 -0
  65. data/ext/cadical/cadical/src/format.hpp +36 -0
  66. data/ext/cadical/cadical/src/frattracer.cpp +277 -0
  67. data/ext/cadical/cadical/src/frattracer.hpp +67 -0
  68. data/ext/cadical/cadical/src/gates.cpp +766 -0
  69. data/ext/cadical/cadical/src/heap.hpp +212 -0
  70. data/ext/cadical/cadical/src/idruptracer.cpp +566 -0
  71. data/ext/cadical/cadical/src/idruptracer.hpp +112 -0
  72. data/ext/cadical/cadical/src/instantiate.cpp +365 -0
  73. data/ext/cadical/cadical/src/instantiate.hpp +45 -0
  74. data/ext/cadical/cadical/src/internal.cpp +1265 -0
  75. data/ext/cadical/cadical/src/internal.hpp +1941 -0
  76. data/ext/cadical/cadical/src/inttypes.hpp +34 -0
  77. data/ext/cadical/cadical/src/ipasir.cpp +47 -0
  78. data/ext/cadical/cadical/src/ipasir.h +37 -0
  79. data/ext/cadical/cadical/src/kitten.c +2599 -0
  80. data/ext/cadical/cadical/src/kitten.h +97 -0
  81. data/ext/cadical/cadical/src/level.hpp +33 -0
  82. data/ext/cadical/cadical/src/lidruptracer.cpp +657 -0
  83. data/ext/cadical/cadical/src/lidruptracer.hpp +122 -0
  84. data/ext/cadical/cadical/src/limit.cpp +146 -0
  85. data/ext/cadical/cadical/src/limit.hpp +168 -0
  86. data/ext/cadical/cadical/src/logging.cpp +214 -0
  87. data/ext/cadical/cadical/src/logging.hpp +98 -0
  88. data/ext/cadical/cadical/src/lookahead.cpp +520 -0
  89. data/ext/cadical/cadical/src/lratchecker.cpp +833 -0
  90. data/ext/cadical/cadical/src/lratchecker.hpp +168 -0
  91. data/ext/cadical/cadical/src/lrattracer.cpp +200 -0
  92. data/ext/cadical/cadical/src/lrattracer.hpp +61 -0
  93. data/ext/cadical/cadical/src/lucky.cpp +506 -0
  94. data/ext/cadical/cadical/src/message.cpp +218 -0
  95. data/ext/cadical/cadical/src/message.hpp +65 -0
  96. data/ext/cadical/cadical/src/minimize.cpp +224 -0
  97. data/ext/cadical/cadical/src/mobical.cpp +5588 -0
  98. data/ext/cadical/cadical/src/occs.cpp +52 -0
  99. data/ext/cadical/cadical/src/occs.hpp +36 -0
  100. data/ext/cadical/cadical/src/options.cpp +359 -0
  101. data/ext/cadical/cadical/src/options.hpp +442 -0
  102. data/ext/cadical/cadical/src/parse.cpp +471 -0
  103. data/ext/cadical/cadical/src/parse.hpp +75 -0
  104. data/ext/cadical/cadical/src/phases.cpp +56 -0
  105. data/ext/cadical/cadical/src/phases.hpp +19 -0
  106. data/ext/cadical/cadical/src/probe.cpp +990 -0
  107. data/ext/cadical/cadical/src/profile.cpp +107 -0
  108. data/ext/cadical/cadical/src/profile.hpp +283 -0
  109. data/ext/cadical/cadical/src/proof.cpp +691 -0
  110. data/ext/cadical/cadical/src/proof.hpp +125 -0
  111. data/ext/cadical/cadical/src/propagate.cpp +584 -0
  112. data/ext/cadical/cadical/src/queue.cpp +90 -0
  113. data/ext/cadical/cadical/src/queue.hpp +74 -0
  114. data/ext/cadical/cadical/src/radix.hpp +180 -0
  115. data/ext/cadical/cadical/src/random.cpp +207 -0
  116. data/ext/cadical/cadical/src/random.h +44 -0
  117. data/ext/cadical/cadical/src/random.hpp +98 -0
  118. data/ext/cadical/cadical/src/range.hpp +125 -0
  119. data/ext/cadical/cadical/src/reap.cpp +127 -0
  120. data/ext/cadical/cadical/src/reap.hpp +28 -0
  121. data/ext/cadical/cadical/src/reduce.cpp +278 -0
  122. data/ext/cadical/cadical/src/reluctant.hpp +82 -0
  123. data/ext/cadical/cadical/src/rephase.cpp +402 -0
  124. data/ext/cadical/cadical/src/report.cpp +313 -0
  125. data/ext/cadical/cadical/src/resources.cpp +160 -0
  126. data/ext/cadical/cadical/src/resources.hpp +16 -0
  127. data/ext/cadical/cadical/src/restart.cpp +178 -0
  128. data/ext/cadical/cadical/src/restore.cpp +267 -0
  129. data/ext/cadical/cadical/src/score.cpp +51 -0
  130. data/ext/cadical/cadical/src/score.hpp +16 -0
  131. data/ext/cadical/cadical/src/shrink.cpp +507 -0
  132. data/ext/cadical/cadical/src/signal.cpp +136 -0
  133. data/ext/cadical/cadical/src/signal.hpp +33 -0
  134. data/ext/cadical/cadical/src/solution.cpp +50 -0
  135. data/ext/cadical/cadical/src/solver.cpp +1871 -0
  136. data/ext/cadical/cadical/src/stable.cpp +31 -0
  137. data/ext/cadical/cadical/src/stack.h +110 -0
  138. data/ext/cadical/cadical/src/stats.cpp +920 -0
  139. data/ext/cadical/cadical/src/stats.hpp +418 -0
  140. data/ext/cadical/cadical/src/subsume.cpp +645 -0
  141. data/ext/cadical/cadical/src/sweep.cpp +1960 -0
  142. data/ext/cadical/cadical/src/sweep.hpp +61 -0
  143. data/ext/cadical/cadical/src/terminal.cpp +38 -0
  144. data/ext/cadical/cadical/src/terminal.hpp +96 -0
  145. data/ext/cadical/cadical/src/ternary.cpp +450 -0
  146. data/ext/cadical/cadical/src/testing.hpp +24 -0
  147. data/ext/cadical/cadical/src/tier.cpp +189 -0
  148. data/ext/cadical/cadical/src/tracer.hpp +186 -0
  149. data/ext/cadical/cadical/src/transred.cpp +253 -0
  150. data/ext/cadical/cadical/src/unstable.cpp +29 -0
  151. data/ext/cadical/cadical/src/util.cpp +129 -0
  152. data/ext/cadical/cadical/src/util.hpp +181 -0
  153. data/ext/cadical/cadical/src/var.cpp +39 -0
  154. data/ext/cadical/cadical/src/var.hpp +22 -0
  155. data/ext/cadical/cadical/src/veripbtracer.cpp +427 -0
  156. data/ext/cadical/cadical/src/veripbtracer.hpp +106 -0
  157. data/ext/cadical/cadical/src/version.cpp +107 -0
  158. data/ext/cadical/cadical/src/version.hpp +13 -0
  159. data/ext/cadical/cadical/src/vivify.cpp +1893 -0
  160. data/ext/cadical/cadical/src/vivify.hpp +50 -0
  161. data/ext/cadical/cadical/src/walk.cpp +1088 -0
  162. data/ext/cadical/cadical/src/walk.hpp +91 -0
  163. data/ext/cadical/cadical/src/walk_full_occs.cpp +966 -0
  164. data/ext/cadical/cadical/src/warmup.cpp +403 -0
  165. data/ext/cadical/cadical/src/watch.cpp +126 -0
  166. data/ext/cadical/cadical/src/watch.hpp +77 -0
  167. data/ext/cadical/cadical_ext.c +778 -0
  168. data/ext/cadical/extconf.rb +26 -0
  169. data/lib/cadical/version.rb +3 -0
  170. data/lib/cadical.rb +12 -0
  171. metadata +218 -0
@@ -0,0 +1,190 @@
1
+ #ifndef _clause_hpp_INCLUDED
2
+ #define _clause_hpp_INCLUDED
3
+
4
+ #include "util.hpp"
5
+ #include <climits>
6
+ #include <cstdint>
7
+ #include <cstdlib>
8
+
9
+ namespace CaDiCaL {
10
+
11
+ /*------------------------------------------------------------------------*/
12
+
13
+ typedef int *literal_iterator;
14
+ typedef const int *const_literal_iterator;
15
+
16
+ /*------------------------------------------------------------------------*/
17
+
18
+ // The 'Clause' data structure is very important. There are usually many
19
+ // clauses and accessing them is a hot-spot. Thus we use common
20
+ // optimizations to reduce memory and improve cache usage, even though this
21
+ // induces some complexity in understanding the code.
22
+ //
23
+ // The most important optimization is to 'embed' the actual literals in the
24
+ // clause. This requires a variadic size structure and thus strictly is not
25
+ // 'C' conform, but supported by all compilers we used. The alternative is
26
+ // to store the actual literals somewhere else, which not only needs more
27
+ // memory but more importantly also requires another memory access and thus
28
+ // is very costly.
29
+
30
+ #define USED_SIZE 5
31
+ struct Clause {
32
+ union {
33
+ int64_t id; // Used to create LRAT-style proofs
34
+ Clause *copy; // Only valid if 'moved', then that's where to.
35
+ //
36
+ // The 'copy' field is only valid for 'moved' clauses in the moving
37
+ // garbage collector 'copy_non_garbage_clauses' for keeping clauses
38
+ // compactly in a contiguous memory arena. Otherwise, so almost all of
39
+ // the time, 'id' is valid. See 'collect.cpp' for details.
40
+ };
41
+ unsigned used
42
+ : USED_SIZE; // resolved in conflict analysis since last 'reduce'
43
+ bool conditioned : 1; // Tried for globally blocked clause elimination.
44
+ bool covered : 1; // Already considered for covered clause elimination.
45
+ bool enqueued : 1; // Enqueued on backward queue.
46
+ bool frozen : 1; // Temporarily frozen (in covered clause elimination).
47
+ bool garbage : 1; // can be garbage collected unless it is a 'reason'
48
+ bool gate : 1; // Clause part of a gate (function definition).
49
+ bool hyper : 1; // redundant hyper binary or ternary resolved
50
+ bool instantiated : 1; // tried to instantiate
51
+ bool moved : 1; // moved during garbage collector ('copy' valid)
52
+ bool reason : 1; // reason / antecedent clause can not be collected
53
+ bool redundant : 1; // aka 'learned' so not 'irredundant' (original)
54
+ bool transred : 1; // already checked for transitive reduction
55
+ bool subsume : 1; // not checked in last subsumption round
56
+ bool swept : 1; // clause used to sweep equivalences
57
+ bool flushed : 1; // garbage in proof deleted binaries
58
+ bool vivified : 1; // clause already vivified
59
+ bool vivify : 1; // clause scheduled to be vivified
60
+
61
+ // The glucose level ('LBD' or short 'glue') is a heuristic value for the
62
+ // expected usefulness of a learned clause, where smaller glue is consider
63
+ // more useful. During learning the 'glue' is determined as the number of
64
+ // decisions in the learned clause. Thus the glue of a clause is a strict
65
+ // upper limit on the smallest number of decisions needed to make it
66
+ // propagate. For instance a binary clause will propagate if one of its
67
+ // literals is set to false. Similarly a learned clause with glue 1 can
68
+ // propagate after one decision, one with glue 2 after 2 decisions etc.
69
+ // In some sense the glue is an abstraction of the size of the clause.
70
+ //
71
+ // See the IJCAI'09 paper by Audemard & Simon for more details. We
72
+ // switched back and forth between keeping the glue stored in a clause and
73
+ // using it only initially to determine whether it is kept, that is
74
+ // survives clause reduction. The latter strategy is not bad but also
75
+ // does not allow to use glue values for instance in 'reduce'.
76
+ //
77
+ // More recently we also update the glue and promote clauses to lower
78
+ // level tiers during conflict analysis. The idea of using three tiers is
79
+ // also due to Chanseok Oh and thus used in all recent 'Maple...' solvers.
80
+ // Tier one are the always kept clauses with low glue at most
81
+ // 'opts.reducetier1glue' (default '2'). The second tier contains all
82
+ // clauses with glue larger than 'opts.reducetier1glue' but smaller or
83
+ // equal than 'opts.reducetier2glue' (default '6'). The third tier
84
+ // consists of clauses with glue larger than 'opts.reducetier2glue'.
85
+ //
86
+ // Clauses in tier one are not deleted in 'reduce'. Clauses in tier
87
+ // two require to be unused in two consecutive 'reduce' intervals before
88
+ // being collected while for clauses in tier three not being used since
89
+ // the last 'reduce' call makes them deletion candidates. Clauses derived
90
+ // by hyper binary or ternary resolution (even though small and thus with
91
+ // low glue) are always removed if they remain unused during one interval.
92
+ // See 'mark_useless_redundant_clauses_as_garbage' in 'reduce.cpp' and
93
+ // 'bump_clause' in 'analyze.cpp'.
94
+ //
95
+ int glue;
96
+
97
+ int size; // Actual size of 'literals' (at least 2).
98
+ int pos; // Position of last watch replacement [Gent'13].
99
+
100
+ // This 'flexible array member' is of variadic 'size' (and actually
101
+ // shrunken if strengthened) and keeps the literals close to the header of
102
+ // the clause to avoid another pointer dereference, which would be costly.
103
+
104
+ // In earlier versions we used 'literals[2]' to fake it (in order to
105
+ // support older Microsoft compilers even though this feature is in C99)
106
+ // and at the same time being able to overlay the first two literals with
107
+ // the 'copy' field above, as having a flexible array member inside a
108
+ // union is not allowed. Now compilers start to figure out that those
109
+ // literals can be accessed with indices larger than 1 and produce
110
+ // warnings. After having the 'id' field mandatory we now overlay that
111
+ // one with the copy field.
112
+
113
+ // However, it turns out that even though flexible array members are in
114
+ // C99 they are not in C11++, and therefore pedantic compilation with
115
+ // '--pedantic' fails completely. Therefore we still support as
116
+ // alternative faked flexible array members, which unfortunately need
117
+ // then again more care when accessing the literals outside the faked
118
+ // virtual sizes and the compiler can somehow figure that out, because
119
+ // that would in turn produce a warning.
120
+
121
+ #ifndef NFLEXIBLE
122
+ int literals[];
123
+ #else
124
+ int literals[2];
125
+ #endif
126
+
127
+ // Supports simple range based for loops over clauses.
128
+
129
+ literal_iterator begin () { return literals; }
130
+ literal_iterator end () { return literals + size; }
131
+
132
+ const_literal_iterator begin () const { return literals; }
133
+ const_literal_iterator end () const { return literals + size; }
134
+
135
+ static size_t bytes (int size) {
136
+
137
+ // Memory sanitizer insists that clauses put into consecutive memory in
138
+ // the arena are still 8 byte aligned. We could also allocate 8 byte
139
+ // aligned memory there. However, assuming the real memory foot print
140
+ // of a clause is 8 bytes anyhow, we just allocate 8 byte aligned memory
141
+ // all the time (even if allocated outside of the arena).
142
+ //
143
+ assert (size > 1);
144
+ const size_t header_bytes = sizeof (Clause);
145
+ const size_t actual_literal_bytes = size * sizeof (int);
146
+ size_t combined_bytes = header_bytes + actual_literal_bytes;
147
+ #ifdef NFLEXIBLE
148
+ const size_t faked_literals_bytes = sizeof ((Clause *) 0)->literals;
149
+ combined_bytes -= faked_literals_bytes;
150
+ #endif
151
+ size_t aligned_bytes = align (combined_bytes, alignof (Clause *));
152
+ return aligned_bytes;
153
+ }
154
+
155
+ size_t bytes () const { return bytes (size); }
156
+
157
+ // Check whether this clause is ready to be collected and deleted. The
158
+ // 'reason' flag is only there to protect reason clauses in 'reduce',
159
+ // which does not backtrack to the root level. If garbage collection is
160
+ // triggered from a preprocessor, which backtracks to the root level, then
161
+ // 'reason' is false for sure. We want to use the same garbage collection
162
+ // code though for both situations and thus hide here this variance.
163
+ //
164
+ bool collect () const { return !reason && garbage; }
165
+ };
166
+
167
+ struct clause_smaller_size {
168
+ bool operator() (const Clause *a, const Clause *b) {
169
+ return a->size < b->size;
170
+ }
171
+ };
172
+
173
+ /*------------------------------------------------------------------------*/
174
+
175
+ // Place literals over the same variable close to each other. This would
176
+ // allow eager removal of identical literals and detection of tautological
177
+ // clauses but is only currently used for better logging (see also
178
+ // 'opts.logsort' in 'logging.cpp').
179
+
180
+ struct clause_lit_less_than {
181
+ bool operator() (int a, int b) const {
182
+ using namespace std;
183
+ int s = abs (a), t = abs (b);
184
+ return s < t || (s == t && a < b);
185
+ }
186
+ };
187
+
188
+ } // namespace CaDiCaL
189
+
190
+ #endif