Skip to content

Commit 3c49e1b

Browse files
committed
resolution.jl: Add conveniency methods for is_satisfiable.
The new methods allow testing a formula that has not been converted to a normal form yet.
1 parent bfc1e6a commit 3c49e1b

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/resolution.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,20 @@ function is_satisfiable(clauses::CNF; maxsearchdepth=Inf)
187187
else
188188
is_satisfiable(clauses, maxsearchdepth=maxsearchdepth-1)
189189
end
190-
end
190+
end
191+
192+
function is_satisfiable(formula::Formula; maxsearchdepth=Inf)
193+
is_satisfiable(
194+
get_conjunctive_normal_form(
195+
get_removed_quantifier_form(
196+
get_skolem_normal_form(
197+
get_prenex_normal_form(
198+
get_quantified_variables_form(
199+
get_renamed_quantifiers_form(
200+
formula)))))),
201+
maxsearchdepth=maxsearchdepth
202+
)
203+
end
204+
205+
is_satisfiable(formula::String; maxsearchdepth=Inf) =
206+
is_satisfiable(Formula(formula), maxsearchdepth=maxsearchdepth)

test/test_resolution.jl

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
function get_normalized_form(formula::String)
2-
get_conjunctive_normal_form(
3-
get_removed_quantifier_form(
4-
get_skolem_normal_form(
5-
get_prenex_normal_form(
6-
get_quantified_variables_form(
7-
get_renamed_quantifiers_form(
8-
Formula(formula)))))))
9-
end
10-
111
function testsatisfiability(formula, issatisfiable; maxsearchdepth=5)
122
if issatisfiable == false
133
@customtest is_satisfiable(formula, maxsearchdepth=maxsearchdepth) == false
@@ -18,14 +8,14 @@ end
188

199
@testset "is_satisfiable" begin
2010
# Basic tests, easy to verify by hand.
21-
testsatisfiability(get_normalized_form("P(x) & ~P(x)"), false)
22-
testsatisfiability(get_normalized_form("P(x) & ~P(y)"), true)
23-
testsatisfiability(get_normalized_form("(P(x) & ~P(y)) & (~P(x) & P(y))"), false)
24-
testsatisfiability(get_normalized_form("(P(x) & ~P(y)) | (C(y) & ~C(y))"), true)
25-
testsatisfiability(get_normalized_form("A() & (B() | ~C()) & ~B() & C()"), false)
26-
testsatisfiability(get_normalized_form("*{x}(P(x) & ~P(f(x)))"), false)
27-
testsatisfiability(get_normalized_form("(S(x,p) | G(p)) & (~L(x) | G(p)) & (~S(x,p)) & (~G(p))"), false)
28-
testsatisfiability(get_normalized_form("(S(x,p) | G(p)) & (~L(x) | G(p))"), true)
11+
testsatisfiability("P(x) & ~P(x)", false)
12+
testsatisfiability("P(x) & ~P(y)", true)
13+
testsatisfiability("(P(x) & ~P(y)) & (~P(x) & P(y))", false)
14+
testsatisfiability("(P(x) & ~P(y)) | (C(y) & ~C(y))", true)
15+
testsatisfiability("A() & (B() | ~C()) & ~B() & C()", false)
16+
testsatisfiability("*{x}(P(x) & ~P(f(x)))", false)
17+
testsatisfiability("(S(x,p) | G(p)) & (~L(x) | G(p)) & (~S(x,p)) & (~G(p))", false)
18+
testsatisfiability("(S(x,p) | G(p)) & (~L(x) | G(p))", true)
2919

3020
# Test based on "Logik für Informatiker", exercise 76.
3121
testsatisfiability(CNF([
@@ -36,10 +26,10 @@ end
3626
]), false)
3727

3828
# Test based on "Logik für Informatiker", exercise 76.
39-
testsatisfiability(get_normalized_form("((~*{x}(~S(x, p) | L(x))) | G(p)) & ((~?{x}S(x,p)) & (~G(p)))"), false)
29+
testsatisfiability("((~*{x}(~S(x, p) | L(x))) | G(p)) & ((~?{x}S(x,p)) & (~G(p)))", false)
4030

4131
# Test based on "Logik für Informatiker", exercise 76.
42-
testsatisfiability(get_normalized_form("((~*{x}(~S(x, p) | L(x))) | G(p)) & ((~?{x}S(x,p)) & (G(p)))"), true)
32+
testsatisfiability("((~*{x}(~S(x, p) | L(x))) | G(p)) & ((~?{x}S(x,p)) & (G(p)))", true)
4333

4434
# Test based on "Logik für Informatiker", exercise 80.
4535
testsatisfiability(CNF([

0 commit comments

Comments
 (0)