src/HOL/Tools/res_reconstruct.ML
changeset 30190 479806475f3c
parent 29597 0f4f36779ca7
child 30857 3fb9345721e4
equal deleted inserted replaced
30189:3633f560f4c3 30190:479806475f3c
    49 datatype stree = Int of int | Br of string * stree list;
    49 datatype stree = Int of int | Br of string * stree list;
    50 
    50 
    51 fun atom x = Br(x,[]);
    51 fun atom x = Br(x,[]);
    52 
    52 
    53 fun scons (x,y) = Br("cons", [x,y]);
    53 fun scons (x,y) = Br("cons", [x,y]);
    54 val listof = foldl scons (atom "nil");
    54 val listof = List.foldl scons (atom "nil");
    55 
    55 
    56 (*Strings enclosed in single quotes, e.g. filenames*)
    56 (*Strings enclosed in single quotes, e.g. filenames*)
    57 val quoted = $$"'" |-- Scan.repeat (~$$"'") --| $$"'" >> implode;
    57 val quoted = $$"'" |-- Scan.repeat (~$$"'") --| $$"'" >> implode;
    58 
    58 
    59 (*Intended for $true and $false*)
    59 (*Intended for $true and $false*)
   241   end;
   241   end;
   242 
   242 
   243 fun gen_all_vars t = fold_rev Logic.all (OldTerm.term_vars t) t;
   243 fun gen_all_vars t = fold_rev Logic.all (OldTerm.term_vars t) t;
   244 
   244 
   245 fun ints_of_stree_aux (Int n, ns) = n::ns
   245 fun ints_of_stree_aux (Int n, ns) = n::ns
   246   | ints_of_stree_aux (Br(_,ts), ns) = foldl ints_of_stree_aux ns ts;
   246   | ints_of_stree_aux (Br(_,ts), ns) = List.foldl ints_of_stree_aux ns ts;
   247 
   247 
   248 fun ints_of_stree t = ints_of_stree_aux (t, []);
   248 fun ints_of_stree t = ints_of_stree_aux (t, []);
   249 
   249 
   250 fun decode_tstp vt0 (name, role, ts, annots) ctxt =
   250 fun decode_tstp vt0 (name, role, ts, annots) ctxt =
   251   let val deps = case annots of NONE => [] | SOME (source,_) => ints_of_stree source
   251   let val deps = case annots of NONE => [] | SOME (source,_) => ints_of_stree source
   360 fun eq_types t = t aconv HOLogic.true_const;
   360 fun eq_types t = t aconv HOLogic.true_const;
   361 
   361 
   362 fun replace_dep (old:int, new) dep = if dep=old then new else [dep];
   362 fun replace_dep (old:int, new) dep = if dep=old then new else [dep];
   363 
   363 
   364 fun replace_deps (old:int, new) (lno, t, deps) =
   364 fun replace_deps (old:int, new) (lno, t, deps) =
   365       (lno, t, foldl (op union_int) [] (map (replace_dep (old, new)) deps));
   365       (lno, t, List.foldl (op union_int) [] (map (replace_dep (old, new)) deps));
   366 
   366 
   367 (*Discard axioms; consolidate adjacent lines that prove the same clause, since they differ
   367 (*Discard axioms; consolidate adjacent lines that prove the same clause, since they differ
   368   only in type information.*)
   368   only in type information.*)
   369 fun add_prfline ((lno, "axiom", t, []), lines) =  (*axioms are not proof lines*)
   369 fun add_prfline ((lno, "axiom", t, []), lines) =  (*axioms are not proof lines*)
   370       if eq_types t (*must be clsrel/clsarity: type information, so delete refs to it*)
   370       if eq_types t (*must be clsrel/clsarity: type information, so delete refs to it*)
   390 fun add_nonnull_prfline ((lno, t, []), lines) = (*no dependencies, so a conjecture clause*)
   390 fun add_nonnull_prfline ((lno, t, []), lines) = (*no dependencies, so a conjecture clause*)
   391      if eq_types t (*must be type information, tfree_tcs, clsrel, clsarity: delete refs to it*)
   391      if eq_types t (*must be type information, tfree_tcs, clsrel, clsarity: delete refs to it*)
   392      then delete_dep lno lines
   392      then delete_dep lno lines
   393      else (lno, t, []) :: lines
   393      else (lno, t, []) :: lines
   394   | add_nonnull_prfline ((lno, t, deps), lines) = (lno, t, deps) :: lines
   394   | add_nonnull_prfline ((lno, t, deps), lines) = (lno, t, deps) :: lines
   395 and delete_dep lno lines = foldr add_nonnull_prfline [] (map (replace_deps (lno, [])) lines);
   395 and delete_dep lno lines = List.foldr add_nonnull_prfline [] (map (replace_deps (lno, [])) lines);
   396 
   396 
   397 fun bad_free (Free (a,_)) = String.isPrefix "sko_" a
   397 fun bad_free (Free (a,_)) = String.isPrefix "sko_" a
   398   | bad_free _ = false;
   398   | bad_free _ = false;
   399 
   399 
   400 (*TVars are forbidden in goals. Also, we don't want lines with <2 dependencies.
   400 (*TVars are forbidden in goals. Also, we don't want lines with <2 dependencies.
   433 fun decode_tstp_file cnfs ctxt th sgno thm_names =
   433 fun decode_tstp_file cnfs ctxt th sgno thm_names =
   434   let val _ = trace "\ndecode_tstp_file: start\n"
   434   let val _ = trace "\ndecode_tstp_file: start\n"
   435       val tuples = map (dest_tstp o tstp_line o explode) cnfs
   435       val tuples = map (dest_tstp o tstp_line o explode) cnfs
   436       val _ = trace (Int.toString (length tuples) ^ " tuples extracted\n")
   436       val _ = trace (Int.toString (length tuples) ^ " tuples extracted\n")
   437       val ctxt = ProofContext.set_mode ProofContext.mode_schematic ctxt
   437       val ctxt = ProofContext.set_mode ProofContext.mode_schematic ctxt
   438       val raw_lines = foldr add_prfline [] (decode_tstp_list ctxt tuples)
   438       val raw_lines = List.foldr add_prfline [] (decode_tstp_list ctxt tuples)
   439       val _ = trace (Int.toString (length raw_lines) ^ " raw_lines extracted\n")
   439       val _ = trace (Int.toString (length raw_lines) ^ " raw_lines extracted\n")
   440       val nonnull_lines = foldr add_nonnull_prfline [] raw_lines
   440       val nonnull_lines = List.foldr add_nonnull_prfline [] raw_lines
   441       val _ = trace (Int.toString (length nonnull_lines) ^ " nonnull_lines extracted\n")
   441       val _ = trace (Int.toString (length nonnull_lines) ^ " nonnull_lines extracted\n")
   442       val (_,lines) = foldr (add_wanted_prfline ctxt) (0,[]) nonnull_lines
   442       val (_,lines) = List.foldr (add_wanted_prfline ctxt) (0,[]) nonnull_lines
   443       val _ = trace (Int.toString (length lines) ^ " lines extracted\n")
   443       val _ = trace (Int.toString (length lines) ^ " lines extracted\n")
   444       val (ccls,fixes) = ResAxioms.neg_conjecture_clauses th sgno
   444       val (ccls,fixes) = ResAxioms.neg_conjecture_clauses th sgno
   445       val _ = trace (Int.toString (length ccls) ^ " conjecture clauses\n")
   445       val _ = trace (Int.toString (length ccls) ^ " conjecture clauses\n")
   446       val ccls = map forall_intr_vars ccls
   446       val ccls = map forall_intr_vars ccls
   447       val _ = if !Output.debugging then app (fn th => trace ("\nccl: " ^ string_of_thm th)) ccls
   447       val _ = if !Output.debugging then app (fn th => trace ("\nccl: " ^ string_of_thm th)) ccls