src/HOL/Tools/sat_funcs.ML
changeset 33035 15eab423e573
parent 32970 fbd2bb2489a8
child 33228 cf8da4f3f92b
equal deleted inserted replaced
33034:66ef64a5f122 33035:15eab423e573
   216 let
   216 let
   217 	(* Thm.cterm -> int option *)
   217 	(* Thm.cterm -> int option *)
   218 	fun index_of_literal chyp = (
   218 	fun index_of_literal chyp = (
   219 		case (HOLogic.dest_Trueprop o Thm.term_of) chyp of
   219 		case (HOLogic.dest_Trueprop o Thm.term_of) chyp of
   220 		  (Const ("Not", _) $ atom) =>
   220 		  (Const ("Not", _) $ atom) =>
   221 			SOME (~(valOf (Termtab.lookup atom_table atom)))
   221 			SOME (~ (the (Termtab.lookup atom_table atom)))
   222 		| atom =>
   222 		| atom =>
   223 			SOME (valOf (Termtab.lookup atom_table atom))
   223 			SOME (the (Termtab.lookup atom_table atom))
   224 	) handle TERM _ => NONE;  (* 'chyp' is not a literal *)
   224 	) handle TERM _ => NONE;  (* 'chyp' is not a literal *)
   225 
   225 
   226 	(* int -> Thm.thm * (int * Thm.cterm) list *)
   226 	(* int -> Thm.thm * (int * Thm.cterm) list *)
   227 	fun prove_clause id =
   227 	fun prove_clause id =
   228 		case Array.sub (clauses, id) of
   228 		case Array.sub (clauses, id) of
   242 			end
   242 			end
   243 		| NO_CLAUSE =>
   243 		| NO_CLAUSE =>
   244 			(* prove the clause, using information from 'clause_table' *)
   244 			(* prove the clause, using information from 'clause_table' *)
   245 			let
   245 			let
   246 				val _      = if !trace_sat then tracing ("Proving clause #" ^ string_of_int id ^ " ...") else ()
   246 				val _      = if !trace_sat then tracing ("Proving clause #" ^ string_of_int id ^ " ...") else ()
   247 				val ids    = valOf (Inttab.lookup clause_table id)
   247 				val ids    = the (Inttab.lookup clause_table id)
   248 				val clause = resolve_raw_clauses (map prove_clause ids)
   248 				val clause = resolve_raw_clauses (map prove_clause ids)
   249 				val _      = Array.update (clauses, id, RAW_CLAUSE clause)
   249 				val _      = Array.update (clauses, id, RAW_CLAUSE clause)
   250 				val _      = if !trace_sat then tracing ("Replay chain successful; clause stored at #" ^ string_of_int id) else ()
   250 				val _      = if !trace_sat then tracing ("Replay chain successful; clause stored at #" ^ string_of_int id) else ()
   251 			in
   251 			in
   252 				clause
   252 				clause
   365 				val cnf_cterm = cprop_of clauses_thm
   365 				val cnf_cterm = cprop_of clauses_thm
   366 				val cnf_thm   = Thm.assume cnf_cterm
   366 				val cnf_thm   = Thm.assume cnf_cterm
   367 				(* [[c_1 && ... && c_n] |- c_1, ..., [c_1 && ... && c_n] |- c_n] *)
   367 				(* [[c_1 && ... && c_n] |- c_1, ..., [c_1 && ... && c_n] |- c_n] *)
   368 				val cnf_clauses = Conjunction.elim_balanced (length sorted_clauses) cnf_thm
   368 				val cnf_clauses = Conjunction.elim_balanced (length sorted_clauses) cnf_thm
   369 				(* initialize the clause array with the given clauses *)
   369 				(* initialize the clause array with the given clauses *)
   370 				val max_idx    = valOf (Inttab.max_key clause_table)
   370 				val max_idx    = the (Inttab.max_key clause_table)
   371 				val clause_arr = Array.array (max_idx + 1, NO_CLAUSE)
   371 				val clause_arr = Array.array (max_idx + 1, NO_CLAUSE)
   372 				val _          = fold (fn thm => fn idx => (Array.update (clause_arr, idx, ORIG_CLAUSE thm); idx+1)) cnf_clauses 0
   372 				val _          = fold (fn thm => fn idx => (Array.update (clause_arr, idx, ORIG_CLAUSE thm); idx+1)) cnf_clauses 0
   373 				(* replay the proof to derive the empty clause *)
   373 				(* replay the proof to derive the empty clause *)
   374 				(* [c_1 && ... && c_n] |- False *)
   374 				(* [c_1 && ... && c_n] |- False *)
   375 				val raw_thm = replay_proof atom_table clause_arr (clause_table, empty_id)
   375 				val raw_thm = replay_proof atom_table clause_arr (clause_table, empty_id)