let rec condToDNF cond =
(*Typage : condition --> liste de liste de termes (disjonction de conjonction de termes)
DNF(terme) = {{terme}}
DNF(a or b) = DNF(a) \/ DNF(b)
DNF(a and b) = Composition (DNF(a),DNF(b))
DNF(not a) = tmp = DNF(a)
composition (tmp)
negation de chaque terme
*)
match cond with
| TOr (c1, c2) -> (condToDNF c1)@(condToDNF c2)
| TAnd (c1, c2) ->
let d1,d2=(condToDNF c1), (condToDNF c2) in
List.fold_left
(fun lclause clauses2 ->
(List.map (fun clauses1 -> clauses1@clauses2) d1) @ lclause
)
[] d2
| TNot (c) ->
begin
match c with
| TOr (c1, c2) -> condToDNF (TAnd(TNot(c1),TNot(c2)))
| TAnd (c1, c2) -> condToDNF (TOr (TNot(c1),TNot(c2)))
| TNot (c1) -> condToDNF c1
| _ as t -> [[TNot(t)]]
end
| _ as t -> [[t]]