src/HOL/Tools/prop_logic.ML
changeset 55436 9781e17dcc23
parent 45740 132a3e1c0fe5
child 58322 f13f6e27d68e
equal deleted inserted replaced
55435:662e0fd39823 55436:9781e17dcc23
   256   if is_cnf fm then fm
   256   if is_cnf fm then fm
   257   else
   257   else
   258     let
   258     let
   259       val fm' = nnf fm
   259       val fm' = nnf fm
   260       (* 'new' specifies the next index that is available to introduce an auxiliary variable *)
   260       (* 'new' specifies the next index that is available to introduce an auxiliary variable *)
   261       (* int ref *)
       
   262       val new = Unsynchronized.ref (maxidx fm' + 1)
   261       val new = Unsynchronized.ref (maxidx fm' + 1)
   263       (* unit -> int *)
       
   264       fun new_idx () = let val idx = !new in new := idx+1; idx end
   262       fun new_idx () = let val idx = !new in new := idx+1; idx end
   265       (* replaces 'And' by an auxiliary variable (and its definition) *)
   263       (* replaces 'And' by an auxiliary variable (and its definition) *)
   266       (* prop_formula -> prop_formula * prop_formula list *)
       
   267       fun defcnf_or (And x) =
   264       fun defcnf_or (And x) =
   268             let
   265             let
   269               val i = new_idx ()
   266               val i = new_idx ()
   270             in
   267             in
   271               (* Note that definitions are in NNF, but not CNF. *)
   268               (* Note that definitions are in NNF, but not CNF. *)
   277               val (fm2', defs2) = defcnf_or fm2
   274               val (fm2', defs2) = defcnf_or fm2
   278             in
   275             in
   279               (Or (fm1', fm2'), defs1 @ defs2)
   276               (Or (fm1', fm2'), defs1 @ defs2)
   280             end
   277             end
   281         | defcnf_or fm = (fm, [])
   278         | defcnf_or fm = (fm, [])
   282       (* prop_formula -> prop_formula *)
       
   283       fun defcnf_from_nnf True = True
   279       fun defcnf_from_nnf True = True
   284         | defcnf_from_nnf False = False
   280         | defcnf_from_nnf False = False
   285         | defcnf_from_nnf (BoolVar i) = BoolVar i
   281         | defcnf_from_nnf (BoolVar i) = BoolVar i
   286       (* 'fm' must be a variable since the formula is in NNF *)
   282       (* 'fm' must be a variable since the formula is in NNF *)
   287         | defcnf_from_nnf (Not fm) = Not fm
   283         | defcnf_from_nnf (Not fm) = Not fm