Skip to content

Commit 7f678c3

Browse files
authored
improvement: Balance Formula in Expression Conversion (#7)
1 parent 91e3ace commit 7f678c3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/crux/formula.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ defmodule Crux.Formula do
113113
@spec from_expression(Expression.t(variable)) :: t(variable) when variable: term()
114114
def from_expression(expression) do
115115
expression
116-
# Expand Booleans so that they do not become variables
117-
|> Expression.run(& &1)
116+
|> Expression.balance()
117+
|> Expression.simplify()
118118
|> case do
119119
true ->
120120
@simple_true

test/crux/formula_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ defmodule Crux.FormulaTest do
2323

2424
assert %Formula{
2525
cnf: [
26-
# :a or not :c
27-
[1, -2],
28-
# not :b or not :c
29-
[-3, -2],
3026
# :a or :d
31-
[1, 4],
27+
[1, 2],
3228
# not :b or :d
33-
[-3, 4]
29+
[-3, 2],
30+
# :a or not :c
31+
[1, -4],
32+
# not :b or not :c
33+
[-3, -4]
3434
],
3535
bindings: %{
3636
1 => :a,
37-
2 => :c,
37+
2 => :d,
3838
3 => :b,
39-
4 => :d
39+
4 => :c
4040
}
4141
} = result
4242
end

0 commit comments

Comments
 (0)