let simplify clause =
let isFalse = ref false in
let result = ref [] in
List.iter
(fun term ->
match term with
| PTrue
| PNot(PFalse) -> ()
| PFalse
| PNot(PTrue) -> isFalse:=true
| PIndexedExp(s1) as t ->
if
List.fold_left
(fun toKeep term ->
match term with
| PIndexedExp(s2) -> toKeep && (not (expAreEqual s1 s2))
| PNot(PIndexedExp(s2)) when (expAreEqual s1 s2) -> isFalse:=true;false
| _ -> toKeep
)
true
!result
then
result:=t::!result
| PNot(PIndexedExp(s1)) as t ->
if
List.fold_left
(fun toKeep term ->
match term with
| PNot(PIndexedExp(s2)) -> toKeep && (not (expAreEqual s1 s2))
| PIndexedExp(s2) when (expAreEqual s1 s2) -> isFalse:=true;false
| _ -> toKeep
)
true
!result
then
result:=t::!result
| _ as t ->
result:=t::!result
)
clause ;
if !isFalse then []
else if !result=[] then [PTrue]
else !result