Skip to content

Commit 43f02cf

Browse files
committed
Merge branch 'development'
2 parents faa674e + 21f1459 commit 43f02cf

File tree

7 files changed

+116
-50
lines changed

7 files changed

+116
-50
lines changed

NEWS.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Version 4.0.1
2+
-------------
3+
4+
- updated README to point to the 2024 system description
5+
- removed redundant line in congruence closure
6+
- fixed proof chain generation for matching ITE
7+
- fixed getting size of watches for `--compact`
8+
- more precise completion in congruence
9+
- writing DIMACS to `<stdout>` with `-o -`
10+
- fixed reporting in congruence
11+
- fixed DIMACS writing
12+
113
Version 4.0.0
214
-------------
315

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
4.0.1

src/application.c

+43-19
Original file line numberDiff line numberDiff line change
@@ -809,30 +809,54 @@ static int run_application (kissat *solver, int argc, char **argv,
809809
close_proof (&application);
810810
#endif
811811
kissat_section (solver, "result");
812-
if (res == 20) {
813-
printf ("s UNSATISFIABLE\n");
814-
fflush (stdout);
815-
} else if (res == 10) {
816-
#ifndef NDEBUG
817-
if (GET_OPTION (check))
818-
kissat_check_satisfying_assignment (solver);
819-
#endif
820-
printf ("s SATISFIABLE\n");
821-
fflush (stdout);
822-
if (application.witness)
823-
kissat_print_witness (solver, application.max_var,
824-
application.partial);
812+
if (application.output_path && !strcmp (application.output_path, "-")) {
813+
const char *status;
814+
if (res == 20)
815+
status = "UNSATISFIABLE";
816+
else if (res == 10)
817+
status = "SATISFIABLE";
818+
else
819+
status = "UNKNOWN";
820+
kissat_message (solver,
821+
"not printing 's %s' status line "
822+
"when writing DIMACS to '<stdout>'",
823+
status);
825824
} else {
826-
printf ("s UNKNOWN\n");
827-
fflush (stdout);
825+
if (res == 20) {
826+
printf ("s UNSATISFIABLE\n");
827+
fflush (stdout);
828+
} else if (res == 10) {
829+
#ifndef NDEBUG
830+
if (GET_OPTION (check))
831+
kissat_check_satisfying_assignment (solver);
832+
#endif
833+
printf ("s SATISFIABLE\n");
834+
fflush (stdout);
835+
if (application.witness)
836+
kissat_print_witness (solver, application.max_var,
837+
application.partial);
838+
} else {
839+
printf ("s UNKNOWN\n");
840+
fflush (stdout);
841+
}
828842
}
829843
if (application.output_path) {
830844
// TODO want to use 'struct file' from 'file.h'?
831-
FILE *file = fopen (application.output_path, "w");
832-
if (!file)
833-
ERROR ("could not write DIMACS file '%s'", application.output_path);
845+
const char *path = application.output_path;
846+
bool close_file;
847+
FILE *file;
848+
if (!strcmp (path, "-")) {
849+
close_file = false;
850+
file = stdout;
851+
} else {
852+
close_file = true;
853+
file = fopen (path, "w");
854+
if (!file)
855+
ERROR ("could not write DIMACS file '%s'", path);
856+
}
834857
kissat_write_dimacs (solver, file);
835-
fclose (file);
858+
if (close_file)
859+
fclose (file);
836860
}
837861
#ifndef QUIET
838862
kissat_print_statistics (solver);

src/congruence.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,6 @@ static void add_binary_clause (closure *closure, unsigned a, unsigned b) {
834834
unit = b;
835835
else if (!a_value && b_value < 0)
836836
unit = a;
837-
else if (a == b)
838-
unit = a;
839837
if (unit != INVALID_LIT) {
840838
(void) !learn_congruence_unit (closure, unit);
841839
return;
@@ -1259,7 +1257,7 @@ static void add_ite_matching_proof_chain (closure *closure, gate *g,
12591257
PUSH_STACK (*unsimplified, cond);
12601258
SIMPLIFY_AND_ADD_TO_PROOF_CHAIN ();
12611259
unsimplified->end--;
1262-
PUSH_STACK (*unsimplified, cond);
1260+
PUSH_STACK (*unsimplified, not_cond);
12631261
SIMPLIFY_AND_ADD_TO_PROOF_CHAIN ();
12641262
unsimplified->end--;
12651263
SIMPLIFY_AND_ADD_TO_PROOF_CHAIN ();

src/factor.c

+27-12
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ static double distinct_paths (factoring *factoring, unsigned src_lit,
270270
const unsigned signed_src_lit = src_lit ^ sign;
271271
watches *const watches = &WATCHES (signed_src_lit);
272272
uint64_t ticks =
273-
1 + kissat_cache_lines (SIZE_STACK (*watches), sizeof (watch));
273+
1 + kissat_cache_lines (SIZE_WATCHES (*watches), sizeof (watch));
274274
for (all_binary_large_watches (watch, *watches)) {
275275
if (watch.type.binary) {
276276
const unsigned other = watch.binary.lit;
@@ -559,7 +559,7 @@ static void factorize_next (factoring *factoring, unsigned next,
559559
assert (min_lit != INVALID_LIT);
560560
watches *min_watches = all_watches + min_lit;
561561
unsigned c_size = c->size;
562-
ticks += 1 + kissat_cache_lines (SIZE_STACK (*min_watches),
562+
ticks += 1 + kissat_cache_lines (SIZE_WATCHES (*min_watches),
563563
sizeof (watch));
564564
for (all_binary_large_watches (min_watch, *min_watches)) {
565565
if (min_watch.type.binary)
@@ -893,7 +893,7 @@ adjust_scores_and_phases_of_fresh_varaibles (factoring *factoring) {
893893
}
894894
}
895895

896-
static void run_factorization (kissat *solver, uint64_t limit) {
896+
static bool run_factorization (kissat *solver, uint64_t limit) {
897897
factoring factoring;
898898
init_factoring (solver, &factoring, limit);
899899
schedule_factorization (&factoring);
@@ -903,7 +903,7 @@ static void run_factorization (kissat *solver, uint64_t limit) {
903903
#endif
904904
uint64_t *ticks = &solver->statistics.factor_ticks;
905905
kissat_extremely_verbose (
906-
solver, "factorization limit of %" PRIu64 " ticks", limit);
906+
solver, "factorization limit of %" PRIu64 " ticks", limit - *ticks);
907907
while (!done && !kissat_empty_heap (&factoring.schedule)) {
908908
const unsigned first =
909909
kissat_pop_max_heap (solver, &factoring.schedule);
@@ -946,9 +946,11 @@ static void run_factorization (kissat *solver, uint64_t limit) {
946946
}
947947
release_quotients (&factoring);
948948
}
949+
bool completed = kissat_empty_heap (&factoring.schedule);
949950
adjust_scores_and_phases_of_fresh_varaibles (&factoring);
950951
release_factoring (&factoring);
951952
REPORT (!factored, 'f');
953+
return completed;
952954
}
953955

954956
static void connect_clauses_to_factor (kissat *solver) {
@@ -1069,8 +1071,14 @@ void kissat_factor (kissat *solver) {
10691071
if (!GET_OPTION (factor))
10701072
return;
10711073
statistics *s = &solver->statistics;
1072-
if (solver->limits.factor.marked >= s->literals_factor)
1074+
if (solver->limits.factor.marked >= s->literals_factor) {
1075+
kissat_extremely_verbose (
1076+
solver,
1077+
"factorization skipped as no literals have been marked to be added "
1078+
"(%" PRIu64 " < %" PRIu64,
1079+
solver->limits.factor.marked, s->literals_factor);
10731080
return;
1081+
}
10741082
START (factor);
10751083
INC (factorizations);
10761084
kissat_phase (solver, "factorization", GET (factorizations),
@@ -1089,33 +1097,40 @@ void kissat_factor (kissat *solver) {
10891097
}
10901098
#ifndef QUIET
10911099
struct {
1092-
int64_t variables, clauses, ticks;
1100+
int64_t variables, binary, clauses, ticks;
10931101
} before, after, delta;
10941102
before.variables = s->variables_extension + s->variables_original;
1095-
before.clauses = BINARY_CLAUSES;
1103+
before.binary = BINARY_CLAUSES;
1104+
before.clauses = IRREDUNDANT_CLAUSES;
10961105
before.ticks = s->factor_ticks;
10971106
#endif
10981107
kissat_enter_dense_mode (solver, 0);
10991108
connect_clauses_to_factor (solver);
1100-
run_factorization (solver, limit);
1109+
bool completed = run_factorization (solver, limit);
11011110
kissat_resume_sparse_mode (solver, false, 0);
11021111
#ifndef QUIET
11031112
after.variables = s->variables_extension + s->variables_original;
1104-
after.clauses = BINARY_CLAUSES;
1113+
after.binary = BINARY_CLAUSES;
1114+
after.clauses = IRREDUNDANT_CLAUSES;
11051115
after.ticks = s->factor_ticks;
11061116
delta.variables = after.variables - before.variables;
1117+
delta.binary = before.binary - after.binary;
11071118
delta.clauses = before.clauses - after.clauses;
1108-
delta.ticks = before.ticks - after.ticks;
1119+
delta.ticks = after.ticks - before.ticks;
11091120
kissat_very_verbose (solver, "used %f million factorization ticks",
11101121
delta.ticks * 1e-6);
11111122
kissat_phase (solver, "factorization", GET (factorizations),
11121123
"introduced %" PRId64 " extension variables %.0f%%",
11131124
delta.variables,
11141125
kissat_percent (delta.variables, before.variables));
11151126
kissat_phase (solver, "factorization", GET (factorizations),
1116-
"removed %" PRId64 " binary clauses %.0f%%", delta.clauses,
1127+
"removed %" PRId64 " binary clauses %.0f%%", delta.binary,
1128+
kissat_percent (delta.binary, before.binary));
1129+
kissat_phase (solver, "factorization", GET (factorizations),
1130+
"removed %" PRId64 " large clauses %.0f%%", delta.clauses,
11171131
kissat_percent (delta.clauses, before.clauses));
11181132
#endif
1119-
solver->limits.factor.marked = s->literals_factor;
1133+
if (completed)
1134+
solver->limits.factor.marked = s->literals_factor;
11201135
STOP (factor);
11211136
}

src/krite.c

+27-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,34 @@
66
#include <inttypes.h>
77

88
void kissat_write_dimacs (kissat *solver, FILE *file) {
9-
fprintf (file, "p cnf %u %" PRIu64 "\n", VARS, BINIRR_CLAUSES);
9+
size_t imported = SIZE_STACK (solver->import);
10+
if (imported)
11+
imported--;
12+
fprintf (file, "p cnf %zu %" PRIu64 "\n", imported, BINIRR_CLAUSES);
1013
assert (solver->watching);
11-
for (all_literals (ilit))
12-
for (all_binary_large_watches (watch, WATCHES (ilit)))
13-
if (watch.type.binary) {
14-
const unsigned iother = watch.binary.lit;
15-
if (iother < ilit)
16-
continue;
17-
const int elit = kissat_export_literal (solver, ilit);
18-
const int eother = kissat_export_literal (solver, iother);
19-
fprintf (file, "%d %d 0\n", elit, eother);
20-
}
14+
if (solver->watching) {
15+
for (all_literals (ilit))
16+
for (all_binary_blocking_watches (watch, WATCHES (ilit)))
17+
if (watch.type.binary) {
18+
const unsigned iother = watch.binary.lit;
19+
if (iother < ilit)
20+
continue;
21+
const int elit = kissat_export_literal (solver, ilit);
22+
const int eother = kissat_export_literal (solver, iother);
23+
fprintf (file, "%d %d 0\n", elit, eother);
24+
}
25+
} else {
26+
for (all_literals (ilit))
27+
for (all_binary_large_watches (watch, WATCHES (ilit)))
28+
if (watch.type.binary) {
29+
const unsigned iother = watch.binary.lit;
30+
if (iother < ilit)
31+
continue;
32+
const int elit = kissat_export_literal (solver, ilit);
33+
const int eother = kissat_export_literal (solver, iother);
34+
fprintf (file, "%d %d 0\n", elit, eother);
35+
}
36+
}
2137
for (all_clauses (c))
2238
if (!c->garbage && !c->redundant) {
2339
for (all_literals_in_clause (ilit, c)) {

test/testsolve.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ static void schedule_solve_job_with_option (int expected, const char *opt,
1111
tissat_warning ("Skipping unreadable '%s'", path);
1212
return;
1313
}
14-
char cmd[256];
15-
assert (strlen (path) + strlen (opt) + 32 < sizeof cmd);
16-
sprintf (cmd, "%s%s", opt, path);
17-
assert (strlen (cmd) < sizeof cmd);
14+
size_t len = strlen (opt) + strlen (path) + 1;
15+
char * cmd = malloc (len);
16+
strcpy (cmd, opt);
17+
strcat (cmd, path);
1818
tissat_schedule_application (expected, cmd);
19+
free (cmd);
1920
scheduled++;
2021
}
2122

0 commit comments

Comments
 (0)